colored-rs / colored

(Rust) Coloring terminal so simple you already know how to do it !
Mozilla Public License 2.0
1.73k stars 83 forks source link

Allow conversion from ColoredString to Error #86

Closed spenserblack closed 11 months ago

spenserblack commented 4 years ago

A string can be converted to a Box<dyn Error>, allowing something like

fn main() -> Result<(), Box<dyn Error>> {
    Err("ERROR")?
}

This PR also allows type conversion from ColoredString to Box<dyn Error>, so you can do

fn main() -> Result<(), Box<dyn Error>> {
    Err("ERROR".red())?
}

And get the expected styling in the error message (see added example).