File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ // option2.rs
2
+ // Make me compile! Execute `rustlings hint option2` for hints
3
+
4
+ // I AM NOT DONE
5
+
6
+ fn main ( ) {
7
+ let optional_value = Some ( String :: from ( "rustlings" ) ) ;
8
+ // Make this an if let statement whose value is "Some" type
9
+ value = optional_value {
10
+ println!( "the value of optional value is: {}" , value) ;
11
+ } else {
12
+ println!( "The optional value doesn't contain anything!" ) ;
13
+ }
14
+
15
+ let mut optional_values_vec: Vec < Option < i8 > > = Vec :: new ( ) ;
16
+ for x in 1 ..10 {
17
+ optional_values_vec. push ( Some ( x) ) ;
18
+ }
19
+
20
+ // make this a while let statement - remember that vector.pop also adds another layer of Option<T>
21
+ // You can stack `Option<T>`'s into while let and if let
22
+ value = optional_values_vec. pop ( ) {
23
+ println ! ( "current value: {}" , value) ;
24
+ }
25
+ }
Original file line number Diff line number Diff line change @@ -534,6 +534,21 @@ and:
534
534
pattern matching
535
535
"""
536
536
537
+ [[exercises ]]
538
+ name = " option2"
539
+ path = " exercises/option/option2.rs"
540
+ mode = " compile"
541
+ hint = """
542
+ check out:
543
+ https://doc.rust-lang.org/rust-by-example/flow_control/if_let.html
544
+ https://doc.rust-lang.org/rust-by-example/flow_control/while_let.html
545
+
546
+ Remember that Options can be stacked in if let and while let.
547
+ For example: Some(Some(variable)) = variable2
548
+
549
+
550
+ """
551
+
537
552
[[exercises ]]
538
553
name = " result1"
539
554
path = " exercises/error_handling/result1.rs"
You can’t perform that action at this time.
0 commit comments