Skip to content

Commit

Permalink
Merge pull request #282 from sanjaykdragon/master
Browse files Browse the repository at this point in the history
feat: added option exercise
  • Loading branch information
fmoko authored Apr 5, 2020
2 parents b135b58 + 3f81714 commit 7ce4294
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions exercises/option/README.md
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 23 additions & 0 deletions exercises/option/option1.rs
Original file line number Diff line number Diff line change
@@ -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;
}
}
14 changes: 14 additions & 0 deletions info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 7ce4294

Please sign in to comment.