Macro genco::push[][src]

macro_rules! push {
    ($dest:expr, |$t:ident| $code:block) => { ... };
    ($dest:expr, $($x:expr),*) => { ... };
    ($dest:expr, $($x:expr,)*) => { ... };
}

Helper macro to reduce boilerplate needed with pushed token expressions.

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

Examples

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

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

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

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

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

Pushing as a block:

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

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

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

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

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