macro_rules! write_fn {
($id:ident, $t:ty, $data:expr) => { ... };
}
Expand description
Write a getter function for a heap-allocated variable.
Makes the getter function available for import into the main crate via use_symbols
.
§Parameters
$id
: the name of the getter function. This must be used when importing withuse_symbols
.$t
: the return type of the getter function.$data
: the data to return from the geter function.
§Example
build.rs
use rustifact::ToTokenStream;
fn main() {
let vecs = vec![vec![1, 2], vec![1, 2, 3], vec![1, 2, 3, 4]];
rustifact::write_fn!(get_vecs, Vec<Vec<u32>>, vecs);
}
src/main.rs
rustifact::use_symbols!(get_vecs);
// The above line is equivalent to the declaration:
// fn get_vecs() -> Vec<Vec<u32>> {
// vec![vec![1, 2], vec![1, 2, 3], vec![1, 2, 3, 4]]
// }
fn main() {
println!("{:?}", get_vecs());
}