[−][src]Function uneval::funcs::to_file
pub fn to_file(
value: impl Serialize,
target: impl AsRef<Path>
) -> Result<(), UnevalError>
Writes generated Rust code to file.
This is probably the most common way to use uneval
. When Cargo runs your crate's build task,
it sets the OUT_DIR
environment variable to the path to build target directory (see
Cargo reference for more).
So, you can use it in two steps:
- Generate the Rust code and write it to temporary file:
let path: std::path::PathBuf = [ std::env::var("OUT_DIR").expect("No build target path set"), "file_name.rs".into() ].iter().collect(); uneval::to_file(value, path).expect("Write failed");
- Include the generated Rust code wherever it is needed:
ⓘThis example is not tested
let value = include!(concat!(env!(OUT_DIR), "/file_name.rs"));