mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-03 01:09:18 +00:00
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
|
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]]
|
[[exercises]]
|
||||||
name = "result1"
|
name = "result1"
|
||||||
path = "exercises/error_handling/result1.rs"
|
path = "exercises/error_handling/result1.rs"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user