Skip to content

Meanining not clear in ch9.2 [The ? Operator can be used in functions that return Result] section #2912

Closed
rust-lang/rust
#90751
@asher-gh

Description

@asher-gh
  • I have checked the latest main branch to see if this has already been fixed
  • I have searched existing issues and pull requests for duplicates

URL to the section(s) of the book with this problem:

Description of the problem:
In this para, it is referring if we want to use ? when calling other functions that return Result<T, E>, we can either change the return type of function definition(understandable) or use the match constructs seen earlier(in essence saying don't use ?).

When you’re writing code in a function that doesn’t return one of these types, and you want to use ? when you call other functions that return Result<T, E>, you have two choices to fix this problem. One technique is to change the return type of your function to be Result<T, E> if you have no restrictions preventing that. The other technique is to use a match or one of the Result<T, E> methods to handle the Result<T, E> in whatever way is appropriate.

Suggested fix:
When you’re writing code in a function that doesn’t return one of these types and when you call other functions that return Result<T, E>, you have two choices to handle this. One technique is to change the return type of your function to be Result<T, E> if you have no restrictions preventing that. The other technique is to use a match or one of the Result<T, E> methods to handle the Result<T, E> in whatever way is appropriate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions