diff options
| author | fmoko <mokou@posteo.de> | 2020-04-05 15:58:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-05 15:58:09 +0200 |
| commit | 7ce42941ea3bed02bb7286e90baa27773a59c224 (patch) | |
| tree | 7a28e771225ea2786ab05b77bf516dd2833498a3 | |
| parent | b135b589e0ffa479b7f6071d89a0a185d262a84f (diff) | |
| parent | 3f8171475cd1a660bc6fe1798de8442c0db9efff (diff) | |
Merge pull request #282 from sanjaykdragon/master
feat: added option exercise
| -rw-r--r-- | Cargo.lock | 2 | ||||
| -rw-r--r-- | exercises/option/README.md | 9 | ||||
| -rw-r--r-- | exercises/option/option1.rs | 23 | ||||
| -rw-r--r-- | info.toml | 14 |
4 files changed, 47 insertions, 1 deletions
@@ -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<T>, 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..51c39f5 --- /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<u16>) { + println!("printing: {}", maybe_number.unwrap()); +} + +fn main() { + print_number(13); + print_number(99); + + let mut numbers: [Option<u16>; 5]; + for iter in 0..5 { + let number_to_add: u16 = { + ((iter * 5) + 2) / (4 * 16) + }; + + numbers[iter] = number_to_add; + } +} @@ -521,6 +521,20 @@ 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" mode = "test" |
