2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2014-09-06 20:52:07 +00:00
|
|
|
|
2014-06-25 17:07:37 +00:00
|
|
|
fn match_vecs<'a, T>(l1: &'a [T], l2: &'a [T]) -> &'static str {
|
|
|
|
match (l1, l2) {
|
2016-03-11 10:54:59 +00:00
|
|
|
(&[], &[]) => "both empty",
|
|
|
|
(&[], &[..]) | (&[..], &[]) => "one empty",
|
|
|
|
(&[..], &[..]) => "both non-empty"
|
2014-06-25 17:07:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn match_vecs_cons<'a, T>(l1: &'a [T], l2: &'a [T]) -> &'static str {
|
|
|
|
match (l1, l2) {
|
2016-03-11 10:54:59 +00:00
|
|
|
(&[], &[]) => "both empty",
|
|
|
|
(&[], &[_, ..]) | (&[_, ..], &[]) => "one empty",
|
|
|
|
(&[_, ..], &[_, ..]) => "both non-empty"
|
2014-06-25 17:07:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn match_vecs_snoc<'a, T>(l1: &'a [T], l2: &'a [T]) -> &'static str {
|
|
|
|
match (l1, l2) {
|
2016-03-11 10:54:59 +00:00
|
|
|
(&[], &[]) => "both empty",
|
|
|
|
(&[], &[.., _]) | (&[.., _], &[]) => "one empty",
|
|
|
|
(&[.., _], &[.., _]) => "both non-empty"
|
2014-06-25 17:07:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn match_nested_vecs_cons<'a, T>(l1: Option<&'a [T]>, l2: Result<&'a [T], ()>) -> &'static str {
|
|
|
|
match (l1, l2) {
|
2016-03-11 10:54:59 +00:00
|
|
|
(Some(&[]), Ok(&[])) => "Some(empty), Ok(empty)",
|
|
|
|
(Some(&[_, ..]), Ok(_)) | (Some(&[_, ..]), Err(())) => "Some(non-empty), any",
|
|
|
|
(None, Ok(&[])) | (None, Err(())) | (None, Ok(&[_])) => "None, Ok(less than one element)",
|
|
|
|
(None, Ok(&[_, _, ..])) => "None, Ok(at least two elements)",
|
2014-06-25 17:07:37 +00:00
|
|
|
_ => "other"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn match_nested_vecs_snoc<'a, T>(l1: Option<&'a [T]>, l2: Result<&'a [T], ()>) -> &'static str {
|
|
|
|
match (l1, l2) {
|
2016-03-11 10:54:59 +00:00
|
|
|
(Some(&[]), Ok(&[])) => "Some(empty), Ok(empty)",
|
|
|
|
(Some(&[.., _]), Ok(_)) | (Some(&[.., _]), Err(())) => "Some(non-empty), any",
|
|
|
|
(None, Ok(&[])) | (None, Err(())) | (None, Ok(&[_])) => "None, Ok(less than one element)",
|
|
|
|
(None, Ok(&[.., _, _])) => "None, Ok(at least two elements)",
|
2014-06-25 17:07:37 +00:00
|
|
|
_ => "other"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2015-01-25 21:05:03 +00:00
|
|
|
assert_eq!(match_vecs(&[1, 2], &[2, 3]), "both non-empty");
|
|
|
|
assert_eq!(match_vecs(&[], &[1, 2, 3, 4]), "one empty");
|
2015-03-26 00:06:52 +00:00
|
|
|
assert_eq!(match_vecs::<usize>(&[], &[]), "both empty");
|
2015-01-25 21:05:03 +00:00
|
|
|
assert_eq!(match_vecs(&[1, 2, 3], &[]), "one empty");
|
2014-06-25 17:07:37 +00:00
|
|
|
|
2015-01-25 21:05:03 +00:00
|
|
|
assert_eq!(match_vecs_cons(&[1, 2], &[2, 3]), "both non-empty");
|
|
|
|
assert_eq!(match_vecs_cons(&[], &[1, 2, 3, 4]), "one empty");
|
2015-03-26 00:06:52 +00:00
|
|
|
assert_eq!(match_vecs_cons::<usize>(&[], &[]), "both empty");
|
2015-01-25 21:05:03 +00:00
|
|
|
assert_eq!(match_vecs_cons(&[1, 2, 3], &[]), "one empty");
|
2014-06-25 17:07:37 +00:00
|
|
|
|
2015-01-25 21:05:03 +00:00
|
|
|
assert_eq!(match_vecs_snoc(&[1, 2], &[2, 3]), "both non-empty");
|
|
|
|
assert_eq!(match_vecs_snoc(&[], &[1, 2, 3, 4]), "one empty");
|
2015-03-26 00:06:52 +00:00
|
|
|
assert_eq!(match_vecs_snoc::<usize>(&[], &[]), "both empty");
|
2015-01-25 21:05:03 +00:00
|
|
|
assert_eq!(match_vecs_snoc(&[1, 2, 3], &[]), "one empty");
|
2014-06-25 17:07:37 +00:00
|
|
|
|
2015-02-18 10:42:01 +00:00
|
|
|
assert_eq!(match_nested_vecs_cons(None, Ok::<&[_], ()>(&[4_usize, 2_usize])),
|
2014-08-06 09:59:40 +00:00
|
|
|
"None, Ok(at least two elements)");
|
2015-03-26 00:06:52 +00:00
|
|
|
assert_eq!(match_nested_vecs_cons::<usize>(None, Err(())), "None, Ok(less than one element)");
|
2014-08-06 09:59:40 +00:00
|
|
|
assert_eq!(match_nested_vecs_cons::<bool>(Some::<&[_]>(&[]), Ok::<&[_], ()>(&[])),
|
|
|
|
"Some(empty), Ok(empty)");
|
2015-01-25 21:05:03 +00:00
|
|
|
assert_eq!(match_nested_vecs_cons(Some::<&[_]>(&[1]), Err(())), "Some(non-empty), any");
|
|
|
|
assert_eq!(match_nested_vecs_cons(Some::<&[_]>(&[(42, ())]), Ok::<&[_], ()>(&[(1, ())])),
|
2014-08-06 09:59:40 +00:00
|
|
|
"Some(non-empty), any");
|
2014-06-25 17:07:37 +00:00
|
|
|
|
2015-02-18 10:42:01 +00:00
|
|
|
assert_eq!(match_nested_vecs_snoc(None, Ok::<&[_], ()>(&[4_usize, 2_usize])),
|
2014-08-06 09:59:40 +00:00
|
|
|
"None, Ok(at least two elements)");
|
2015-03-26 00:06:52 +00:00
|
|
|
assert_eq!(match_nested_vecs_snoc::<usize>(None, Err(())), "None, Ok(less than one element)");
|
2014-08-06 09:59:40 +00:00
|
|
|
assert_eq!(match_nested_vecs_snoc::<bool>(Some::<&[_]>(&[]), Ok::<&[_], ()>(&[])),
|
|
|
|
"Some(empty), Ok(empty)");
|
2015-01-25 21:05:03 +00:00
|
|
|
assert_eq!(match_nested_vecs_snoc(Some::<&[_]>(&[1]), Err(())), "Some(non-empty), any");
|
|
|
|
assert_eq!(match_nested_vecs_snoc(Some::<&[_]>(&[(42, ())]), Ok::<&[_], ()>(&[(1, ())])),
|
2014-08-06 09:59:40 +00:00
|
|
|
"Some(non-empty), any");
|
2014-06-25 17:07:37 +00:00
|
|
|
}
|