changed up the exercise, modified the help section
This commit is contained in:
parent
1113b4a172
commit
d4522f2736
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]]
|
||||
|
|
Loading…
Reference in a new issue