Skip to content

Commit 135e5d4

Browse files
committed
feat: added excercise for option
1 parent 8b94790 commit 135e5d4

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
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);
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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,4 +701,18 @@ path = "exercises/conversions/from_str.rs"
701701
mode = "test"
702702
hint = """
703703
If you've already solved try_from_into.rs, then this is almost a copy-paste.
704-
Otherwise, go ahead and solve try_from_into.rs first."""
704+
Otherwise, go ahead and solve try_from_into.rs first."""
705+
706+
[[exercises]]
707+
name = "option1"
708+
path = "exercises/option/option1.rs"
709+
mode = "compile"
710+
hint = """
711+
Check out some functions of Option:
712+
is_some
713+
is_none
714+
unwrap
715+
716+
and:
717+
pattern matching
718+
"""

0 commit comments

Comments
 (0)