Crates.io | include_tt |
lib.rs | include_tt |
version | 1.0.4 |
source | src |
created_at | 2023-07-23 16:35:07.262125 |
updated_at | 2024-05-14 13:18:20.261751 |
description | Macro for embedding (trees, strings, arrays) into macro trees directly from files. |
homepage | https://github.com/clucompany/include_tt.git |
repository | https://github.com/clucompany/include_tt.git |
max_upload_size | |
id | 923838 |
size | 58,483 |
Add this to your Cargo.toml:
[dependencies]
include_tt = "1.0.4"
and this to your source code:
use include_tt::include_tt;
use include_tt::include_tt;
use std::fmt::Write;
// Example demonstrating the usage of include_tt! macro for embedding content from files.
{
// Embedding trees from a file in an arbitrary place of other macros.
let a = 10;
let b = 20;
let mut end_str = String::new();
// Using include_tt! to embed content into a macro.
include_tt! {
let _e = write!(
&mut end_str,
"arg1: {}, arg2: {}",
#include!("./for_examples/full.tt") // this file contains `a, b`.
);
}
// Asserting the result matches the expected output.
assert_eq!(end_str, "arg1: 10, arg2: 20");
}
{
// Loading a string from "full.tt" using include_tt! macro.
let str = include_tt!(
#include_str!("./for_examples/full.tt") // this file contains `a, b`.
);
// Asserting the result matches the expected output.
assert_eq!(str, "a, b");
}
{
// Loading a array from "full.tt" using include_tt! macro.
let array: &'static [u8; 4] = include_tt!(
#include_arr!("./for_examples/full.tt") // this file contains `a, b`.
);
// Asserting the result matches the expected output.
assert_eq!(array, b"a, b");
}
See all
This project has a dual license according to (LICENSE-MIT) and (LICENSE-APACHE-2-0).