feat: added excercise for option
This commit is contained in:
parent
8b9479071c
commit
135e5d47a7
|
@ -592,7 +592,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustlings"
|
name = "rustlings"
|
||||||
version = "2.2.0"
|
version = "2.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"assert_cmd 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -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)
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
14
info.toml
14
info.toml
|
@ -702,3 +702,17 @@ mode = "test"
|
||||||
hint = """
|
hint = """
|
||||||
If you've already solved try_from_into.rs, then this is almost a copy-paste.
|
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
|
||||||
|
"""
|
Loading…
Reference in New Issue