Created
January 7, 2020 02:25
-
-
Save Riey/ef0a72f56f232e6ffb65115e659e1999 to your computer and use it in GitHub Desktop.
rust slice pat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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