We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 38016cb commit d5cae8fCopy full SHA for d5cae8f
solutions/13_error_handling/errors6.rs
@@ -29,6 +29,21 @@ impl ParsePosNonzeroError {
29
}
30
31
32
+/// As an alternative solution, implementing the `From` trait allows for the
33
+/// automatic conversion from a `ParseIntError` into a `ParsePosNonzeroError`
34
+/// using the `?` operator, without the need to call `map_err`.
35
+///
36
+/// ```
37
+/// let x: i64 = s.parse()?;
38
39
40
+/// Traits like `From` will be dealt with in later exercises.
41
+impl From<ParseIntError> for ParsePosNonzeroError {
42
+ fn from(err: ParseIntError) -> Self {
43
+ ParsePosNonzeroError::ParseInt(err)
44
+ }
45
+}
46
+
47
#[derive(PartialEq, Debug)]
48
struct PositiveNonzeroInteger(u64);
49
0 commit comments