2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
2018-09-25 21:51:35 +00:00
|
|
|
#![allow(dead_code)]
|
2018-08-31 13:02:01 +00:00
|
|
|
#![allow(non_camel_case_types)]
|
|
|
|
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2012-04-20 07:54:42 +00:00
|
|
|
enum pattern { tabby, tortoiseshell, calico }
|
|
|
|
enum breed { beagle, rottweiler, pug }
|
2014-05-22 23:57:53 +00:00
|
|
|
type name = String;
|
2012-04-20 07:54:42 +00:00
|
|
|
enum ear_kind { lop, upright }
|
|
|
|
enum animal { cat(pattern), dog(breed), rabbit(name, ear_kind), tiger }
|
|
|
|
|
2014-05-22 23:57:53 +00:00
|
|
|
fn noise(a: animal) -> Option<String> {
|
2012-08-06 19:34:08 +00:00
|
|
|
match a {
|
2014-11-06 08:05:53 +00:00
|
|
|
animal::cat(..) => { Some("meow".to_string()) }
|
|
|
|
animal::dog(..) => { Some("woof".to_string()) }
|
|
|
|
animal::rabbit(..) => { None }
|
2015-10-26 18:10:41 +00:00
|
|
|
animal::tiger => { Some("roar".to_string()) }
|
2012-04-20 07:54:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 03:43:17 +00:00
|
|
|
pub fn main() {
|
2014-11-06 08:05:53 +00:00
|
|
|
assert_eq!(noise(animal::cat(pattern::tabby)), Some("meow".to_string()));
|
|
|
|
assert_eq!(noise(animal::dog(breed::pug)), Some("woof".to_string()));
|
|
|
|
assert_eq!(noise(animal::rabbit("Hilbert".to_string(), ear_kind::upright)), None);
|
|
|
|
assert_eq!(noise(animal::tiger), Some("roar".to_string()));
|
2013-02-14 19:47:00 +00:00
|
|
|
}
|