Macro include_tt

Source
include_tt!() { /* proc-macro */ }
Expand description

Macro for including trees, strings, arrays from files.

Multiple occurrences of groups are supported.

use include_tt::include_tt;
use std::fmt::Write;

{ // Embedding compiler trees from a file in an arbitrary place of other macros.
	let a = 10;
	let b = 20;

	let mut end_str = String::new();
	include_tt! {
		let _e = write!(
			&mut end_str,

			"arg1: {}, arg2: {}",
			#include!("./examples/full.tt") // this file contains `a, b`.
		);
	}
	assert_eq!(end_str, "arg1: 10, arg2: 20");
}

{
	let str = include_tt!(
		#include_str!("./examples/full.tt") // this file contains `a, b`.
	);
	assert_eq!(str, "a, b");
}

{
	let array: &'static [u8; 4] = include_tt!(
		#include_arr!("./examples/full.tt") // this file contains `a, b`.
	);
	assert_eq!(array, b"a, b");
}