@@ -906,17 +906,17 @@ let guess: u32 = match guess.trim().parse() {
906
906
Err(_) => continue,
907
907
};
908
908
` ` `
909
-
910
909
This is how you generally move from ‘crash on error’ to ‘actually handle the
911
- error’, by switching from ` expect()` to a ` match` statement. The ` Result`
912
- returned by ` parse()` is an ` enum` like ` Ordering` , but in this case, each
913
- variant has some data associated with it: ` Ok` is a success, and ` Err` is a
910
+ error’, by switching from ` expect()` to a ` match` statement. A ` Result` is
911
+ returned by ` parse()` , this is an ` enum` like ` Ordering` , but in this case,
912
+ each variant has some data associated with it: ` Ok` is a success, and ` Err` is a
914
913
failure. Each contains more information: the successfully parsed integer, or an
915
- error type. In this case, we ` match` on ` Ok(num)` , which sets the inner value
916
- of the ` Ok` to the name ` num` , and then we return it on the right-hand
917
- side. In the ` Err` case, we don’t care what kind of error it is, so we
918
- use ` _` instead of a name. This ignores the error, and ` continue` causes us
919
- to go to the next iteration of the ` loop` .
914
+ error type. In this case, we ` match` on ` Ok(num)` , which sets the name ` num` to
915
+ the unwrapped ` Ok` value (ythe integer), and then we return it on the
916
+ right-hand side. In the ` Err` case, we don’t care what kind of error it is, so
917
+ we just use the catch all ` _` instead of a name. This catches everything that
918
+ isn' t `Ok`, and `continue` lets us move to the next iteration of the loop; in
919
+ effect, this enables us to ignore all errors and continue with our program.
920
920
921
921
Now we should be good! Let’s try:
922
922
0 commit comments