Function shadow_rs::new_hook

source ·
pub fn new_hook<F>(f: F) -> SdResult<()>
where F: FnOnce(&File) -> SdResult<()>,
Expand description

Identical to new, but additionally accepts an output hook. The hook receives the output file of shadow-rs, and it can add additional entries to the output of shadow-rs by writing to this file. Note that since the output will be compiled as a Rust module, inserting invalid Rust code will lead to a compile error later on.

§Example

// build.rs

fn main() -> shadow_rs::SdResult<()> {
   shadow_rs::new_hook(append_write_const)
}

fn append_write_const(mut file: &File) -> SdResult<()> {
   let foo: &str = r#"pub const foo: &str = "foo";"#;
   writeln!(file, "{}", foo)?;
   Ok(())
}