File tree Expand file tree Collapse file tree 4 files changed +47
-1
lines changed
Expand file tree Collapse file tree 4 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -520,6 +520,20 @@ function `unwrap_or`.
520520Or use an `if let` statement on the result of `pop()` to both destructure
521521a `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 ]]
524538name = " result1"
525539path = " exercises/error_handling/result1.rs"
You can’t perform that action at this time.
0 commit comments