Self rust tokenize
For taking a instance of a structure and generating a proc_macro2::TokenStream
of tokens which generate the structure
=== quote!;
to_tokens
Deriving on a custom type
;
let a = A;
to_tokens == quote!;
The use case may be: sharing a structure between a crate that deals with instances of it and a proc macro crate which generates tokens that build the instances in a exported proc macro
/// Base definition crate
/// Proc macro crate
use SpecialStructure;
/// Main crate
generate_from_input === make_special_structure!
note that the derived token stream is not scoped, you have to import the structures themselves
Why self_rust_tokenize::SelfRustTokenize
trait and not quote::ToTokens
?
quote::ToTokens
is defined on many types in std to return a more primitive representation of themselves and can lose their type structure. On the other hand self_rust_tokenize::SelfRustTokenize
implementations on std types keeps the type constructor information. Thus a new trait (self_rust_tokenize::SelfRustTokenize
) is needed to prevent implementation conflicts.
e.g.
=== quote!;
to_tokens === quote!;
to_tokens