cargo_emit

Macro warning

Source
macro_rules! warning {
    (to: $stream:expr, $($args:tt)+) => { ... };
    ($($args:tt)+) => { ... };
}
Expand description

Tells Cargo to print the formatted warning message.

This is equivalent to:

println!("cargo:warning=$args");

§Examples

Useful for showing when something expected (but not critical) has failed.

match std::env::current_dir() {
    Ok(dir) => { /* ... */ }
    Err(error) => cargo_emit::warning!(
        "Something suspicious is happening: {}",
        error,
    ),
}

or, in case you want it to emit to a custom stream:

let mut stdout = std::io::stdout();
match std::env::current_dir() {
    Ok(dir) => { /* ... */ }
    Err(error) => cargo_emit::warning!(
        to: stdout,
        "Something suspicious is happening: {}",
        error,
    ),
}

Assuming you’re building my-crate, you will see:

$ cargo build
   Compiling my-crate v0.1.0 (/path/to/my-crate)
warning: Something suspicious is happening: ...