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