Skip to content

Instantly share code, notes, and snippets.

@Riey
Created January 7, 2020 02:25
Show Gist options
  • Save Riey/ef0a72f56f232e6ffb65115e659e1999 to your computer and use it in GitHub Desktop.
Save Riey/ef0a72f56f232e6ffb65115e659e1999 to your computer and use it in GitHub Desktop.
rust slice pat
fn main() {
#[derive(PartialEq, Debug)]
struct X(u8);
let xs: Vec<X> = vec![X(0), X(1), X(2)];
if let [start @ .., end] = &*xs {
// --- bind on last element, assuming there is one.
// ---------- bind the initial elements, if there are any.
assert_eq!(start, &[X(0), X(1)] as &[X]);
assert_eq!(end, &X(2));
let _: &[X] = start;
let _: &X = end;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment