Skip to content

Commit

Permalink
Add that the ? operator works with From<Err> (#1059)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakex authored Aug 9, 2023
1 parent 737cb9a commit f79e672
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/error-handling/try-operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ Key points:
* Use the `fs::write` call to test out the different scenarios: no file, empty file, file with username.
* The return type of the function has to be compatible with the nested functions it calls. For instance,
a function returning a `Result<T, Err>` can only apply the `?` operator on a function returning a
`Result<AnyT, Err>`. It cannot apply the `?` operator on a function returning a `Result<T, OtherErr>`
or an `Option<AnyT>`. Reciprocally, a function returning an `Option<T>` can only apply the `?` operator
`Result<AnyT, Err>`. It cannot apply the `?` operator on a function returning an `Option<AnyT>` or `Result<T, OtherErr>`
unless `OtherErr` implements `From<Err>`. Reciprocally, a function returning an `Option<T>` can only apply the `?` operator
on a function returning an `Option<AnyT>`.
* You can convert incompatible types into one another with the different `Option` and `Result` methods
such as `Option::ok_or`, `Result::ok`, `Result::err`.
Expand Down

0 comments on commit f79e672

Please sign in to comment.