Slice patterns in Nightly Rust
Dennis Ritchie via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jun 20 20:23:17 PDT 2015
Recently published documentation Nightly Rust. I saw this:
https://doc.rust-lang.org/nightly/book/slice-patterns.html
What do you think about this: a terrible thing or a cool feature?
fn is_symmetric(list: &[u32]) -> bool {
match list {
[] | [_] => true,
[x, inside.., y] if x == y => is_symmetric(inside),
_ => false
}
}
fn main() {
let sym = &[0, 1, 4, 2, 4, 1, 0];
assert!(is_symmetric(sym));
let not_sym = &[0, 1, 7, 2, 4, 1, 0];
assert!(!is_symmetric(not_sym));
}
http://is.gd/TvrXSn
I see this competition slices of D. Also seen are not very clear
design.
More information about the Digitalmars-d
mailing list