3 ms·
You can usually use pattern matching to get around a check followed by an unwrap. I would rewrite your example as: if let [first, ..] = &some_vec {
by ibraheemdev 4y ago
You can usually use pattern matching to get around a check followed by an unwrap. I would rewrite your example as:
if let [first, ..] = &some_vec {
print!("{}", first);
// .. more code
}
- muglug 4y agoThanks, I did not know about that particular solution — that adheres more closely to the idealised pseudocode than any of the other Rust alternatives.