changed up the exercise, modified the help section

This commit is contained in:
Sanjay K 2020-04-07 10:35:55 -04:00
parent 1113b4a172
commit d4522f2736
2 changed files with 13 additions and 4 deletions
exercises/option
info.toml

View file

@ -4,8 +4,9 @@
// I AM NOT DONE
fn main() {
let optional_value = String::from("rustlings");
if let Some(value) = optional_value {
let optional_value = Some(String::from("rustlings"));
//make this an if let statement - value is "Some" type
value = optional_value {
println!("the value of optional value is: {}", value);
} else {
println!("optional value does not have a value!");
@ -13,9 +14,12 @@ fn main() {
let mut optional_values_vec: Vec<Option<i8>> = Vec::new();
for x in 1..10 {
optional_values_vec.push(x);
optional_values_vec.push(Some(x));
}
while let Some(Some(value)) = optional_values_vec.pop() {
// make this a while let statement - remember that vector.pop also adds another layer of Option<T>
// you can stack Option<T>'s into while let and if let
value = optional_values_vec.pop() {
println!("current value: {}", value);
}
}

View file

@ -542,6 +542,11 @@ hint = """
check out:
https://doc.rust-lang.org/rust-by-example/flow_control/if_let.html
https://doc.rust-lang.org/rust-by-example/flow_control/while_let.html
Remember that Options can be stacked in if let and while let.
For example: Some(Some(variable)) = variable2
"""
[[exercises]]