Estrarre il valore da un Option in Rust
Livello 271 battiture
Il metodo unwrap() estrae il valore da Some, ma va in panic se l'Option è None.
Codice Rust
// x è un Option<i32> che contiene Some(5)// unwrap restituisce il valore interno 5 (andrebbe in panic se x fosse None)1fn main() { let x: Option<i32> = Some(5); println!("{}", x.unwrap()); }Output
5
Esercitati a digitare questo codice. I risultati non vengono registrati in classifica.
Simboli in questo codice
I simboli che digiti in questo codice Rust e quante volte compaiono.
(× 4)× 4;× 2"× 2{× 2}× 2,× 1:× 1!× 1.× 1