summaryrefslogtreecommitdiffstats
path: root/examples/08_enum-custom.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-07-02 02:54:21 -0400
committerJesse Luehrs <doy@tozt.net>2014-07-02 02:54:21 -0400
commite620daf3b1a40ae825c625bc4328fb7d2b3ee8b6 (patch)
treefaa469408ee78623eaa8d2720dcbb36096788ca1 /examples/08_enum-custom.rs
downloadintro-to-rust-yapc-na-2014-e620daf3b1a40ae825c625bc4328fb7d2b3ee8b6.tar.gz
intro-to-rust-yapc-na-2014-e620daf3b1a40ae825c625bc4328fb7d2b3ee8b6.zip
initial commitHEADmaster
Diffstat (limited to 'examples/08_enum-custom.rs')
-rw-r--r--examples/08_enum-custom.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/examples/08_enum-custom.rs b/examples/08_enum-custom.rs
new file mode 100644
index 0000000..48d3691
--- /dev/null
+++ b/examples/08_enum-custom.rs
@@ -0,0 +1,21 @@
+enum Color {
+ Red,
+ Green,
+ Blue,
+ Custom(int, int, int),
+}
+
+fn print_color (c: Color) {
+ match c {
+ Red => println!("#ff0000"),
+ Green => println!("#00ff00"),
+ Blue => println!("#0000ff"),
+ Custom(r, g, b) => println!("#{:02x}{:02x}{:02x}", r, g, b),
+ }
+}
+
+fn main () {
+ print_color(Red);
+ print_color(Custom(0x12, 0x45, 0xba));
+}
+