From 135e5d47a7c395aece6f6022117fb20c82f2d3d4 Mon Sep 17 00:00:00 2001 From: Sanjay K Date: Thu, 5 Mar 2020 15:52:54 -0500 Subject: [PATCH 1/5] feat: added excercise for option --- Cargo.lock | 2 +- exercises/option/README.md | 9 +++++++++ exercises/option/option1.rs | 23 +++++++++++++++++++++++ info.toml | 16 +++++++++++++++- 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 exercises/option/README.md create mode 100644 exercises/option/option1.rs diff --git a/Cargo.lock b/Cargo.lock index 9cbe5a1..a08dee5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -592,7 +592,7 @@ dependencies = [ [[package]] name = "rustlings" -version = "2.2.0" +version = "2.2.1" dependencies = [ "assert_cmd 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/exercises/option/README.md b/exercises/option/README.md new file mode 100644 index 0000000..d17b79c --- /dev/null +++ b/exercises/option/README.md @@ -0,0 +1,9 @@ +### Option + +#### Book Sections + +To learn about Option, check out these links: + +- [Option Enum Format](https://doc.rust-lang.org/stable/book/ch10-01-syntax.html#in-enum-definitions) +- [Option Module Documentation](https://doc.rust-lang.org/std/option/) +- [Option Enum Documentation](https://doc.rust-lang.org/std/option/enum.Option.html) diff --git a/exercises/option/option1.rs b/exercises/option/option1.rs new file mode 100644 index 0000000..eb32ccb --- /dev/null +++ b/exercises/option/option1.rs @@ -0,0 +1,23 @@ +//option1.rs +//Make me compile! Execute `rustlings hint option1` for hints + +//I AM NOT DONE + +//you can modify anything EXCEPT for this function's sig +fn print_number(maybe_number: Option) { + println!("printing: {}", *maybe_number); +} + +fn main() { + print_number(13); + print_number(99); + + let mut numbers: [Option; 5]; + for iter in 0..5 { + let number_to_add: u16 = { + ((iter * 5) + 2) / (4 * 16); + }; + + numbers[iter] = number_to_add; + } +} \ No newline at end of file diff --git a/info.toml b/info.toml index 82c22b7..4490551 100644 --- a/info.toml +++ b/info.toml @@ -701,4 +701,18 @@ path = "exercises/conversions/from_str.rs" mode = "test" hint = """ If you've already solved try_from_into.rs, then this is almost a copy-paste. -Otherwise, go ahead and solve try_from_into.rs first.""" \ No newline at end of file +Otherwise, go ahead and solve try_from_into.rs first.""" + +[[exercises]] +name = "option1" +path = "exercises/option/option1.rs" +mode = "compile" +hint = """ +Check out some functions of Option: +is_some +is_none +unwrap + +and: +pattern matching +""" \ No newline at end of file From 6d3a412d4768a06dc69b5f1c9d5ebc9bc7f42650 Mon Sep 17 00:00:00 2001 From: Sanjay K Date: Wed, 11 Mar 2020 13:44:10 -0400 Subject: [PATCH 2/5] Update option1.rs --- exercises/option/option1.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/option/option1.rs b/exercises/option/option1.rs index eb32ccb..c5b67b8 100644 --- a/exercises/option/option1.rs +++ b/exercises/option/option1.rs @@ -5,7 +5,7 @@ //you can modify anything EXCEPT for this function's sig fn print_number(maybe_number: Option) { - println!("printing: {}", *maybe_number); + println!("printing: {}", maybe_number.unwrap()); } fn main() { @@ -20,4 +20,4 @@ fn main() { numbers[iter] = number_to_add; } -} \ No newline at end of file +} From 9788496a8588592e99d66ca9f5428531ce7f3155 Mon Sep 17 00:00:00 2001 From: Sanjay K Date: Wed, 11 Mar 2020 13:44:41 -0400 Subject: [PATCH 3/5] Update option1.rs --- exercises/option/option1.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/option/option1.rs b/exercises/option/option1.rs index c5b67b8..91da0be 100644 --- a/exercises/option/option1.rs +++ b/exercises/option/option1.rs @@ -15,7 +15,7 @@ fn main() { let mut numbers: [Option; 5]; for iter in 0..5 { let number_to_add: u16 = { - ((iter * 5) + 2) / (4 * 16); + ((iter * 5) + 2) / (4 * 16) }; numbers[iter] = number_to_add; From 6deee7e3e92ac717e356b99180acaaf03a54b750 Mon Sep 17 00:00:00 2001 From: Sanjay K Date: Thu, 2 Apr 2020 08:40:59 -0400 Subject: [PATCH 4/5] fixed spacing --- exercises/option/option1.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exercises/option/option1.rs b/exercises/option/option1.rs index eb32ccb..e81620d 100644 --- a/exercises/option/option1.rs +++ b/exercises/option/option1.rs @@ -1,9 +1,9 @@ -//option1.rs -//Make me compile! Execute `rustlings hint option1` for hints +// option1.rs +// Make me compile! Execute `rustlings hint option1` for hints -//I AM NOT DONE +// I AM NOT DONE -//you can modify anything EXCEPT for this function's sig +// you can modify anything EXCEPT for this function's sig fn print_number(maybe_number: Option) { println!("printing: {}", *maybe_number); } From 3f8171475cd1a660bc6fe1798de8442c0db9efff Mon Sep 17 00:00:00 2001 From: Sanjay K Date: Sun, 5 Apr 2020 09:45:07 -0400 Subject: [PATCH 5/5] updated info.toml --- info.toml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/info.toml b/info.toml index 4490551..d8eaef5 100644 --- a/info.toml +++ b/info.toml @@ -520,6 +520,20 @@ function `unwrap_or`. Or use an `if let` statement on the result of `pop()` to both destructure a `Some` value and only print out something if we have a value!""" +[[exercises]] +name = "option1" +path = "exercises/option/option1.rs" +mode = "compile" +hint = """ +Check out some functions of Option: +is_some +is_none +unwrap + +and: +pattern matching +""" + [[exercises]] name = "result1" path = "exercises/error_handling/result1.rs" @@ -701,18 +715,4 @@ path = "exercises/conversions/from_str.rs" mode = "test" hint = """ If you've already solved try_from_into.rs, then this is almost a copy-paste. -Otherwise, go ahead and solve try_from_into.rs first.""" - -[[exercises]] -name = "option1" -path = "exercises/option/option1.rs" -mode = "compile" -hint = """ -Check out some functions of Option: -is_some -is_none -unwrap - -and: -pattern matching -""" \ No newline at end of file +Otherwise, go ahead and solve try_from_into.rs first.""" \ No newline at end of file