2012-04-20 02:54:42 -05:00
|
|
|
enum pattern { tabby, tortoiseshell, calico }
|
|
|
|
enum breed { beagle, rottweiler, pug }
|
2012-07-14 00:57:48 -05:00
|
|
|
type name = ~str;
|
2012-04-20 02:54:42 -05:00
|
|
|
enum ear_kind { lop, upright }
|
|
|
|
enum animal { cat(pattern), dog(breed), rabbit(name, ear_kind), tiger }
|
|
|
|
|
2012-08-20 14:23:37 -05:00
|
|
|
fn noise(a: animal) -> Option<~str> {
|
2012-08-06 14:34:08 -05:00
|
|
|
match a {
|
2012-08-20 14:23:37 -05:00
|
|
|
cat(*) => { Some(~"meow") }
|
|
|
|
dog(*) => { Some(~"woof") }
|
|
|
|
rabbit(*) => { None }
|
|
|
|
tiger(*) => { Some(~"roar") }
|
2012-04-20 02:54:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2012-08-20 14:23:37 -05:00
|
|
|
assert noise(cat(tabby)) == Some(~"meow");
|
|
|
|
assert noise(dog(pug)) == Some(~"woof");
|
|
|
|
assert noise(rabbit(~"Hilbert", upright)) == None;
|
|
|
|
assert noise(tiger) == Some(~"roar");
|
2012-04-20 02:54:42 -05:00
|
|
|
}
|