Derive Macro synthez::ToTokens

source ·
#[derive(ToTokens)]
{
    // Attributes available to this derive:
    #[to_tokens]
}
Expand description

Deriving of a quote::ToTokens implementation.

Arguments

append (mandatory)

Specifies methods to form ToTokens’ output with.

#[derive(ToTokens)]
#[to_tokens(append(foo_tokens, baz_tokens))]
struct Dummy;

impl Dummy {
    fn foo_tokens(&self) -> TokenStream {
        quote! {
            impl Foo for String {}
        }
    }

    fn baz_tokens(&self) -> TokenStream {
        quote! {
            impl Baz for String {}
        }
    }
}

let dummy = Dummy;

assert_eq!(
    quote! { #dummy }.to_string(),
    quote! {
        impl Foo for String {}
        impl Baz for String {}
    }
    .to_string(),
);