rust-proc-macros Questions
6
Solved
I join these two questions in one, as they maybe are related. A few days ago, I started having this error in the [#actix_rt::main] line, before the main function:
proc macro `main` not expanded: ca...
Monoatomic asked 4/5, 2023 at 9:2
5
Solved
I have a compile error involving a macro:
<mdo macros>:6:19: 6:50 error: cannot move out of captured outer variable in an `FnMut` closure
<mdo macros>:6 bind ( $ e , move | $ p | mdo !...
Sidewheel asked 18/2, 2015 at 9:47
4
Solved
I am writing a procedural macro which works fine, but I am having trouble reporting errors in an ergonomic way. Using panic! "works" but is not elegant and does not present the error message to the...
Helenhelena asked 27/1, 2019 at 20:44
2
Solved
I have a proc-macro crate with a macro that, when expanded, needs to use custom trait implementations for Rust built-in types. I tried to define the trait in the same crate, but Rust tells me that ...
Wivinah asked 9/10, 2020 at 23:18
2
Solved
I have a TokenStream that comes from the definition of a Rust function. I want to parse it with syn::parse (and .unrwap()). However, I don't know what the return type is supposed to be:
let ast: ?...
Paraplegia asked 3/8, 2019 at 21:11
1
I am implementing a proc macro, and testing in another crate. When I compile the client crate, there is an error thrown from the invocation site of the proc macro:
error: proc macro panicked
-->...
Sweeps asked 28/8, 2022 at 16:52
1
Solved
I have one proc macro that looks like this:
#[proc_macro_attribute]
pub fn my_macro(_meta: CompilerTokenStream, input: CompilerTokenStream) -> CompilerTokenStream { //* bits of code */ }
Then I...
Bereniceberenson asked 15/4, 2022 at 12:49
2
Solved
Procedural macros live in their own crates, which are compiled for the development machine (so that they can be executed when crates that use them are compiled). Any conditional compilation directi...
Exocentric asked 30/9, 2019 at 23:57
4
Solved
I am implementing a function-like procedural macro which takes a single string literal as an argument, but I don't know how to get the value of the string literal.
If I print the variable, it shows...
Annorah asked 12/4, 2020 at 10:22
1
Solved
I'm trying to create a proc-macro to derive and implement a trait for structs and I need that all fields within the struct implement Display.
How do I check that?
And furthermore how do I check if ...
Exudation asked 27/1, 2022 at 13:46
1
Solved
I am trying to write procedural macros that will accept a Rust enum like
#[repr(u8)]
enum Ty {
A,
B
}
and generate a method for the enum that will let me convert an u8 into an allowed variant li...
Wessling asked 21/2, 2021 at 10:38
2
Solved
I'm looking for the equivalent of file!() & module_path!() in a procedural macro context.
For example, the following doesn't work:
file.rs:
#[some_attribute]
const A: bool = true;
macro.rs...
Triquetrous asked 18/3, 2020 at 11:27
0
I wrote a proc-macro library to accompany a library I'm writing - they go together, with the former being used to abstract away a lot of redundant code in the latter.
I am successfully generating ...
Mandolin asked 12/6, 2020 at 16:32
0
I have created a function-like procedural macro. I call it with a declarative macro as parameter. I was hoping to find a way that the declarative macro is expanded before processing the procedural ...
Jalapa asked 25/4, 2020 at 18:51
2
Solved
I have requirement to get the source location of the caller of every method. I am trying to create a proc_macro_attribute to capture the location and print it.
#[proc_macro_attribute]
pub fn get_l...
Cumber asked 15/3, 2020 at 10:56
1
Solved
I am writing a procedural macro and I need to emit a very long identifier multiple times (potentially because of hygiene, for example). I use quote! to create TokenStreams, but I don't want to repe...
Sind asked 6/1, 2020 at 21:31
2
Solved
When writing a declarative (macro_rules!) macro, we automatically get macro hygiene. In this example, I declare a variable named f in the macro and pass in an identifier f which becomes a local var...
Bucharest asked 6/1, 2020 at 19:59
2
Solved
How should a_proc_macro be defined so it "returns" a 5?
fn main() {
let a = a_proc_macro!();
assert!(a == 5);
}
Aubervilliers asked 18/11, 2019 at 20:6
1
Solved
I have a procedural macro that needs to store semi-persistent state. The state needs to survive compilation runs and should be cleaned up when cargo clean is run.
In the past, I used the ./target d...
Mcmann asked 20/5, 2019 at 6:36
2
Solved
I'm using syn to parse Rust code. When I read a named field's type using field.ty, I get a syn::Type. When I print it using quote!{#ty}.to_string() I get "Option<String>".
How can I get jus...
Wrac asked 20/3, 2019 at 23:56
0
I'm working on a procedural macro that does a lot of work that can slow down compilation considerably. The work done does not effect the semantics of the function; that is, if given the same set of...
Missy asked 21/5, 2019 at 6:1
1
Solved
I am trying to implement custom derive macros for my traits, and they actually work!
However I have a slight problem. I can't seem to find a way to include generic parameters to the trait.
Specif...
Kiyohara asked 17/5, 2019 at 14:40
1
Solved
I created a procedural macro that implements a trait, but in order for this to work I need to get the raw bytes for every field. The problem is how to get the bytes of a field differs depending on ...
Mckenney asked 1/4, 2019 at 8:53
2
Solved
I have a custom struct like the following:
struct MyStruct {
first_field: i32,
second_field: String,
third_field: u16,
}
Is it possible to get the number of struct fields programmatically (li...
Bothy asked 14/1, 2019 at 7:44
1
Solved
Given a string (str), how can one convert that into a TokenStream in Rust?
I've tried using the quote! macro.
let str = "4";
let tokens = quote! { let num = #str; }; // #str is a str not i32
Th...
Lucrative asked 13/1, 2019 at 0:28
1 Next >
© 2022 - 2024 — McMap. All rights reserved.