577 B
577 B
Rust Notes
Options
So options are things that maybe contain values.
let option_a: Option<u8> = Some(8);
let option_b: Option<u8> = None;
To get at the value of a Options you have a few options;
let res:u8 = option_a.unwrap(); // using option.unwrap -> panics if value is none
if let Some(unwrapped1) = option_a {
println!("Unwrapped1 {}", unwrapped1);
}else {
println!("None Unwrapped1");
}
match option_a {
None => println!("None Unwrapped"),
Some(unwrapped1) => {
println!("Unwrapped1 {}", unwrapped1)
},
}