From 1113b4a1721b9e32124605ec7e9eefba22400b1b Mon Sep 17 00:00:00 2001 From: Sanjay K <sanjaykdragon@gmail.com> Date: Mon, 6 Apr 2020 18:50:17 -0400 Subject: [PATCH] added option2 --- exercises/option/option2.rs | 21 +++++++++++++++++++++ info.toml | 10 ++++++++++ 2 files changed, 31 insertions(+) create mode 100644 exercises/option/option2.rs diff --git a/exercises/option/option2.rs b/exercises/option/option2.rs new file mode 100644 index 0000000..c673547 --- /dev/null +++ b/exercises/option/option2.rs @@ -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); + } +} diff --git a/info.toml b/info.toml index ec8da2c..de31dfe 100644 --- a/info.toml +++ b/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"