mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-11-29 22:47:43 +02:00
errors5 solution
This commit is contained in:
@@ -692,24 +692,23 @@ name = "errors5"
|
||||
dir = "13_error_handling"
|
||||
test = false
|
||||
hint = """
|
||||
There are two different possible `Result` types produced within `main()`, which
|
||||
are propagated using `?` operators. How do we declare a return type from
|
||||
`main()` that allows both?
|
||||
There are two different possible `Result` types produced within the `main`
|
||||
function, which are propagated using the `?` operators. How do we declare a
|
||||
return type for the `main` function that allows both?
|
||||
|
||||
Under the hood, the `?` operator calls `From::from` on the error value to
|
||||
convert it to a boxed trait object, a `Box<dyn error::Error>`. This boxed trait
|
||||
object is polymorphic, and since all errors implement the `error::Error` trait,
|
||||
we can capture lots of different errors in one "Box" object.
|
||||
convert it to a boxed trait object, a `Box<dyn Error>`. This boxed trait object
|
||||
is polymorphic, and since all errors implement the `Error` trait, we can capture
|
||||
lots of different errors in one `Box` object.
|
||||
|
||||
Check out this section of the book:
|
||||
Check out this section of The Book:
|
||||
https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html#a-shortcut-for-propagating-errors-the--operator
|
||||
|
||||
Read more about boxing errors:
|
||||
https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/boxing_errors.html
|
||||
|
||||
Read more about using the `?` operator with boxed errors:
|
||||
https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/reenter_question_mark.html
|
||||
"""
|
||||
https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/reenter_question_mark.html"""
|
||||
|
||||
[[exercises]]
|
||||
name = "errors6"
|
||||
|
||||
Reference in New Issue
Block a user