[][src]Macro genco::nested

macro_rules! nested {
    ($dest:expr, |$t:ident| $code:block) => { ... };
    ($dest:expr, $($x:expr),*) => { ... };
    ($dest:expr, $($x:expr,)*) => { ... };
}
👎 Deprecated since 0.5.0:

Use the quote! procedural macro instead.

Helper macro to reduce boilerplate needed with nested token expressions.

All arguments being pushed are cloned, which should be cheap for reference types.

Examples

use genco::{Tokens, Java, ItemStr};

let mut toks = Tokens::<Java>::new();
// id being cloned.
let id = ItemStr::from("hello");

nested!(toks, "foo ", id);
nested!(toks, "bar ", id);

assert_eq!(
    vec![
        "    foo hello",
        "    bar hello",
        ""
    ],
    toks.to_file_vec().unwrap()
);

Pushing as a block:

use genco::{Tokens, Java, ItemStr};

let mut toks = Tokens::<Java>::new();
// id being cloned.
let id = ItemStr::from("hello");

nested!(toks, |t| {
  push!(t, "foo ", id);
  push!(t, "bar ", id);
});

let mut out = Vec::new();
out.push("    foo hello");
out.push("    bar hello");
out.push("");

assert_eq!(out.join("\n").as_str(), toks.to_string().unwrap().as_str());