pub enum Option<T> {
Some(T),
None,
}
Basic usage:
use std::fmt::Debug;
fn match_option<T: Debug>(o: Option<T>) {
match o {
Some(i) => println!("{:?}", i),
None => println!("nothing"),
}
}
let a: Option<i32> = Some(3);
let b: Option<&str> = Some("hello");
let c: Option<char> = Some('A');
let d: Option<u32> = None;
match_option(a);
match_option(b);
match_option(c);
match_option(d); Run
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)