[−][src]Macro genco::quote_in
quote_in!() { /* proc-macro */ }
Same as [quote!], except that it allows for quoting directly to a token stream.
You specify the destination stream as the first argument, followed by a =>
and then the code to generate.
Note that there is a potential issue with reborrowing
Reborrowing
In case you get a borrow issue like the following:
9 | let tokens = &mut tokens;
| ------ help: consider changing this to be mutable: `mut tokens`
...
12 | / quote_in! { tokens =>
13 | | fn #name() -> u32 {
14 | | #(tokens => tokens.append("42");)
15 | | }
16 | | }
| |_____^ cannot borrow as mutable
This is because inner scoped like #(tokens => <code>)
take ownership
of their variable by default. To have it perform a proper reborrow, you can
do the following instead:
use genco::prelude::*; let mut tokens = Tokens::<Rust>::new(); let tokens = &mut tokens; for name in vec!["foo", "bar", "baz"] { quote_in! { tokens => fn #name() -> u32 { #(*tokens => tokens.append("42");) } } }
Examples
use genco::prelude::*; let mut tokens = rust::Tokens::new(); quote_in! { tokens => fn foo() -> u32 { 42 } }
Examples
use genco::prelude::*; let mut tokens = rust::Tokens::new(); quote_in!(tokens => fn hello() -> u32 { 42 }); assert_eq!(vec!["fn hello() -> u32 { 42 }"], tokens.to_file_vec().unwrap());