I know what the $crate
variable is, but as far as I can tell, it can't be used inside procedural macros. Is there another way to achieve a similar effect?
I have an example that roughly requires me to write something like this using quote and nightly Rust
quote!(
struct Foo {
bar: [SomeTrait;#len]
}
)
I need to make sure SomeTrait
is in scope (#len
is referencing an integer outside the scope of the snippet).
I am using procedural macros 2.0 on nightly using quote and syn because proc-macro-hack
didn't work for me. This is the example I'm trying to generalize.
[SomeTrait; #len]
is not a thing you can do, because[T; n]
requiresT: Sized
. See play.rust-lang.org/?gist=bb33e5ba42a7e64af998b014483329f0. Can you clarify the intended result? – dtolnay