Debian Codegraph @

examples/dynamic_colors.rs

raw symbols SCIP
1 extern crate colored;
2 use colored::{Color, Colorize};
3
4 fn main() {
5 // the easy way
6 "blue string yo".color("blue");
7
8 // this will default to white
9 "white string".color("zorglub");
10
11 // the safer way via a Result
12 let color_res = "zorglub".parse(); // <- this returns a Result<Color, ()>
13 "red string".color(color_res.unwrap_or(Color::Red));
14 }