diff --git a/exercises/option/option2.rs b/exercises/option/option2.rs index c673547..77922a3 100644 --- a/exercises/option/option2.rs +++ b/exercises/option/option2.rs @@ -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); } } diff --git a/info.toml b/info.toml index de31dfe..04a90cf 100644 --- a/info.toml +++ b/info.toml @@ -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]]