Skip to content

Commit

Permalink
feat: added excercise for option
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjaykdragon committed Mar 5, 2020
1 parent 8b94790 commit 135e5d4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
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);
}

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;
}
}
16 changes: 15 additions & 1 deletion info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
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
"""

0 comments on commit 135e5d4

Please sign in to comment.