mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-03 09:19:18 +00:00
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
|
// I AM NOT DONE
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let optional_value = String::from("rustlings");
|
let optional_value = Some(String::from("rustlings"));
|
||||||
if let Some(value) = optional_value {
|
//make this an if let statement - value is "Some" type
|
||||||
|
value = optional_value {
|
||||||
println!("the value of optional value is: {}", value);
|
println!("the value of optional value is: {}", value);
|
||||||
} else {
|
} else {
|
||||||
println!("optional value does not have a value!");
|
println!("optional value does not have a value!");
|
||||||
@ -13,9 +14,12 @@ fn main() {
|
|||||||
|
|
||||||
let mut optional_values_vec: Vec<Option<i8>> = Vec::new();
|
let mut optional_values_vec: Vec<Option<i8>> = Vec::new();
|
||||||
for x in 1..10 {
|
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);
|
println!("current value: {}", value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -542,6 +542,11 @@ hint = """
|
|||||||
check out:
|
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/if_let.html
|
||||||
https://doc.rust-lang.org/rust-by-example/flow_control/while_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]]
|
[[exercises]]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user