added option2
This commit is contained in:
parent
7ce42941ea
commit
1113b4a172
21
exercises/option/option2.rs
Normal file
21
exercises/option/option2.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
// option2.rs
|
||||
// Make me compile! Execute `rustlings hint option2` for hints
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let optional_value = String::from("rustlings");
|
||||
if let Some(value) = optional_value {
|
||||
println!("the value of optional value is: {}", value);
|
||||
} else {
|
||||
println!("optional value does not have a value!");
|
||||
}
|
||||
|
||||
let mut optional_values_vec: Vec<Option<i8>> = Vec::new();
|
||||
for x in 1..10 {
|
||||
optional_values_vec.push(x);
|
||||
}
|
||||
while let Some(Some(value)) = optional_values_vec.pop() {
|
||||
println!("current value: {}", value);
|
||||
}
|
||||
}
|
10
info.toml
10
info.toml
|
@ -534,6 +534,16 @@ and:
|
|||
pattern matching
|
||||
"""
|
||||
|
||||
[[exercises]]
|
||||
name = "option2"
|
||||
path = "exercises/option/option2.rs"
|
||||
mode = "compile"
|
||||
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
|
||||
"""
|
||||
|
||||
[[exercises]]
|
||||
name = "result1"
|
||||
path = "exercises/error_handling/result1.rs"
|
||||
|
|
Loading…
Reference in a new issue