macro_rules! dynblock { ($start:literal, $body:expr, $end:literal) => { ... }; (> $start:literal, $body:expr, $end:literal) => { ... }; ($start:expr, $body:expr, $end:literal) => { ... }; (> $start:expr, $body:expr, $end:literal) => { ... }; ($start:literal, $body:expr, $end:expr) => { ... }; (> $start:literal, $body:expr, $end:expr) => { ... }; ($start:expr, $body:expr, $end:expr) => { ... }; (> $start:expr, $body:expr, $end:expr) => { ... }; }
Expand description
Macro for creating a code block with a vector as body
§Example
use codize::{codeln, block, dynblock, Codize};
let expected = r"
fn foo(y: bool) {
if (x()) {
bar();
} else if (y) {
baz();
}
}
";
let body = vec![
block!(format!("if (x()) {{"), [
codeln!("bar();"),
], "}"),
block!(> "else if (y) {", [
codeln!("baz();")
], "}"),
];
let code = dynblock!("\nfn foo(y: bool) {", body, "}");
assert_eq!(expected, code.to_string_with(&Codize::indent(2).set_trailing_newline(true)));