Skip to content

Commit 7ce4294

Browse files
author
fmoko
authored
Merge pull request #282 from sanjaykdragon/master
feat: added option exercise
2 parents b135b58 + 3f81714 commit 7ce4294

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exercises/option/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### Option
2+
3+
#### Book Sections
4+
5+
To learn about Option<T>, check out these links:
6+
7+
- [Option Enum Format](https://doc.rust-lang.org/stable/book/ch10-01-syntax.html#in-enum-definitions)
8+
- [Option Module Documentation](https://doc.rust-lang.org/std/option/)
9+
- [Option Enum Documentation](https://doc.rust-lang.org/std/option/enum.Option.html)

exercises/option/option1.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// option1.rs
2+
// Make me compile! Execute `rustlings hint option1` for hints
3+
4+
// I AM NOT DONE
5+
6+
// you can modify anything EXCEPT for this function's sig
7+
fn print_number(maybe_number: Option<u16>) {
8+
println!("printing: {}", maybe_number.unwrap());
9+
}
10+
11+
fn main() {
12+
print_number(13);
13+
print_number(99);
14+
15+
let mut numbers: [Option<u16>; 5];
16+
for iter in 0..5 {
17+
let number_to_add: u16 = {
18+
((iter * 5) + 2) / (4 * 16)
19+
};
20+
21+
numbers[iter] = number_to_add;
22+
}
23+
}

info.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,20 @@ function `unwrap_or`.
520520
Or use an `if let` statement on the result of `pop()` to both destructure
521521
a `Some` value and only print out something if we have a value!"""
522522

523+
[[exercises]]
524+
name = "option1"
525+
path = "exercises/option/option1.rs"
526+
mode = "compile"
527+
hint = """
528+
Check out some functions of Option:
529+
is_some
530+
is_none
531+
unwrap
532+
533+
and:
534+
pattern matching
535+
"""
536+
523537
[[exercises]]
524538
name = "result1"
525539
path = "exercises/error_handling/result1.rs"

0 commit comments

Comments
 (0)