trpl-zh-cn/listings/ch19-advanced-features/no-listing-09-unwrap-definition/src/lib.rs
2022-02-06 16:43:51 +08:00

18 lines
297 B
Rust
Executable File

enum Option<T> {
Some(T),
None,
}
use crate::Option::*;
// ANCHOR: here
impl<T> Option<T> {
pub fn unwrap(self) -> T {
match self {
Some(val) => val,
None => panic!("called `Option::unwrap()` on a `None` value"),
}
}
}
// ANCHOR_END: here