[][src]Macro genco_macros::quote_in

quote_in!() { /* proc-macro */ }

Behaves the same as quote! while quoting into an existing token stream with <target> => <quoted>.

This macro takes a destination stream followed by an => and the tokens to extend that stream with.

Note that the <target> arguments must be borrowable. So a mutable reference like &mut rust::Tokens will have to be dereferenced when used with this macro.


let mut tokens = rust::Tokens::new();
quote_in!(tokens => hello world);

fn generate_into(tokens: &mut rust::Tokens) {
    quote_in! { *tokens =>
        hello...
        world!
    };
}

Example

use genco::prelude::*;

let mut tokens = rust::Tokens::new();

quote_in! { tokens =>
    fn foo() -> u32 {
        42
    }
}

Use with scopes

quote_in! can be used inside of a quote! through a scope.

use genco::prelude::*;

let tokens: rust::Tokens = quote! {
    fn foo(v: bool) -> u32 {
        #(ref out {
            quote_in! { *out =>
                if v {
                    1
                } else {
                    0
                }
            }
        })
    }
};