2012-12-08 14:22:43 -06:00
|
|
|
struct Foo {
|
|
|
|
string: ~str
|
|
|
|
}
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2012-12-08 14:22:43 -06:00
|
|
|
let x = [
|
|
|
|
Foo { string: ~"foo" },
|
|
|
|
Foo { string: ~"bar" },
|
|
|
|
Foo { string: ~"baz" }
|
|
|
|
];
|
|
|
|
match x {
|
|
|
|
[first, ..tail] => {
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(first.string == ~"foo");
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(tail.len(), 2);
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(tail[0].string == ~"bar");
|
|
|
|
assert!(tail[1].string == ~"baz");
|
2012-12-08 14:22:43 -06:00
|
|
|
|
|
|
|
match tail {
|
|
|
|
[Foo { _ }, _, Foo { _ }, ..tail] => {
|
2013-05-20 19:07:24 -05:00
|
|
|
::std::util::unreachable();
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
|
|
|
[Foo { string: a }, Foo { string: b }] => {
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(a, ~"bar");
|
|
|
|
assert_eq!(b, ~"baz");
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
|
|
|
_ => {
|
2013-05-20 19:07:24 -05:00
|
|
|
::std::util::unreachable();
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {
|
2013-05-20 19:07:24 -05:00
|
|
|
::std::util::unreachable();
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|