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