added option2

This commit is contained in:
Sanjay K 2020-04-06 18:50:17 -04:00
parent 7ce42941ea
commit 1113b4a172
2 changed files with 31 additions and 0 deletions
exercises/option
info.toml

View 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);
}
}

View file

@ -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"