mirror of
https://github.com/google/comprehensive-rust.git
synced 2024-12-14 22:15:54 +02:00
Add that the ?
operator works with From<Err>
(#1059)
This commit is contained in:
parent
737cb9a496
commit
f79e6726cc
@ -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`.
|
||||
|
Loading…
Reference in New Issue
Block a user