rust/src/test/run-pass/issue-1701.rs
Tim Chevalier 37b0549730 Add new syntax for patterns that match the head constructor only
Adds a new kind of pattern C(*) where C is a constructor that may
have any number of fields. This pattern matches any value
constructed with C, without binding names for any of the fields.

Closes #1701.
2012-04-20 00:56:46 -07:00

21 lines
586 B
Rust

enum pattern { tabby, tortoiseshell, calico }
enum breed { beagle, rottweiler, pug }
type name = str;
enum ear_kind { lop, upright }
enum animal { cat(pattern), dog(breed), rabbit(name, ear_kind), tiger }
fn noise(a: animal) -> option<str> {
alt a {
cat(*) { some("meow") }
dog(*) { some("woof") }
rabbit(*) { none }
tiger(*) { some("roar") }
}
}
fn main() {
assert noise(cat(tabby)) == some("meow");
assert noise(dog(pug)) == some("woof");
assert noise(rabbit("Hilbert", upright)) == none;
assert noise(tiger) == some("roar");
}