.expect()
Giống .unwrap(), nhưng khi panic thì Rust sẽ kèm theo message
#![allow(unused)]
fn main() {
let x: Option<&str> = None;
x.expect("fruits are healthy"); // panics: `fruits are healthy`
}
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
.expect()Giống .unwrap(), nhưng khi panic thì Rust sẽ kèm theo message
#![allow(unused)]
fn main() {
let x: Option<&str> = None;
x.expect("fruits are healthy"); // panics: `fruits are healthy`
}