Macro bunt::write

source ·
macro_rules! write {
    ($target:expr, $format_str:literal $(, $arg:expr)* $(,)?) => { ... };
    ($target:expr, [$($format_str:literal),+ $(,)?] $(, $arg:expr)* $(,)?) => { ... };
}
Expand description

Writes formatted data to a termcolor::WriteColor target.

This is a more general version of print as you can specify the destination of the formatted data as first parameter. write also returns a Result<(), std::io::Error> which is Err in case writing to the target or setting the color fails. print! simply panics in that case.

use bunt::termcolor::{ColorChoice, StandardStream};

// Choosing a different color choice, just to show something `println`
// can't do.
let mut stdout = StandardStream::stdout(ColorChoice::Always);
let result = bunt::write!(stdout, "{$red}bad error!{/$}");

if result.is_err() {
    // Writing to stdout failed...
}

See crate-level docs for more information.