31 lines
577 B
Markdown
31 lines
577 B
Markdown
|
# Rust Notes
|
||
|
|
||
|
|
||
|
## Options
|
||
|
|
||
|
So options are things that maybe contain values.
|
||
|
|
||
|
```rust
|
||
|
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;
|
||
|
|
||
|
```rust
|
||
|
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)
|
||
|
},
|
||
|
}
|
||
|
```
|