2020-04-07 14:16:10 -04:00
|
|
|
// option2.rs
|
|
|
|
// Make me compile! Execute `rustlings hint option2` for hints
|
|
|
|
|
|
|
|
// I AM NOT DONE
|
|
|
|
|
|
|
|
fn main() {
|
2021-04-20 05:18:05 -04:00
|
|
|
let optional_word = Some(String::from("rustlings"));
|
2020-05-16 16:48:18 -04:00
|
|
|
// TODO: Make this an if let statement whose value is "Some" type
|
2021-04-20 05:18:05 -04:00
|
|
|
word = optional_word {
|
|
|
|
println!("The word is: {}", word);
|
2020-04-07 14:16:10 -04:00
|
|
|
} else {
|
2021-04-20 05:18:05 -04:00
|
|
|
println!("The optional word doesn't contain anything");
|
2020-04-07 14:16:10 -04:00
|
|
|
}
|
|
|
|
|
2021-04-20 05:18:05 -04:00
|
|
|
let mut optional_integers_vec: Vec<Option<i8>> = Vec::new();
|
2020-04-07 14:16:10 -04:00
|
|
|
for x in 1..10 {
|
2021-04-20 05:18:05 -04:00
|
|
|
optional_integers_vec.push(Some(x));
|
2020-04-07 14:16:10 -04:00
|
|
|
}
|
|
|
|
|
2020-05-16 16:48:18 -04:00
|
|
|
// TODO: make this a while let statement - remember that vector.pop also adds another layer of Option<T>
|
2020-04-07 14:16:10 -04:00
|
|
|
// You can stack `Option<T>`'s into while let and if let
|
2021-04-20 05:18:05 -04:00
|
|
|
integer = optional_integers_vec.pop() {
|
|
|
|
println!("current value: {}", integer);
|
2020-04-07 14:16:10 -04:00
|
|
|
}
|
|
|
|
}
|