I am implementing a procedural macro and I need to provide my own structures to the outside. I need to implement quote::ToTokens
trait for my structures, but I don't understand how. I have tried this code but did not succeed. This code is compilable, but it is not valid:
#[derive(Debug, Serialize, Clone)]
pub enum Enum {
A,
B,
}
impl quote::ToTokens for Enum {
fn to_tokens(&self, tokens: &mut quote::Tokens) {
tokens.append("Enum::B");
}
}
The quote::ToTokens
example does not explain this.
use
for it so it must be prepended with "cratename::" ? Personally I think there must be a method of gettingfully qualified name
for the requested item. P.S. My question implies that your code in your answer is incorrect too :) – Saddletree