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