]> git.proxmox.com Git - rustc.git/blobdiff - vendor/colored/examples/dynamic_colors.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / vendor / colored / examples / dynamic_colors.rs
diff --git a/vendor/colored/examples/dynamic_colors.rs b/vendor/colored/examples/dynamic_colors.rs
new file mode 100755 (executable)
index 0000000..d9861f4
--- /dev/null
@@ -0,0 +1,14 @@
+extern crate colored;
+use colored::*;
+
+fn main() {
+    // the easy way
+    "blue string yo".color("blue");
+
+    // this will default to white
+    "white string".color("zorglub");
+
+    // the safer way via a Result
+    let color_res = "zorglub".parse(); // <- this returns a Result<Color, ()>
+    "red string".color(color_res.unwrap_or(Color::Red));
+}