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