Skip to content

Example code of Result.expect() confused me #2918

@shifujun

Description

@shifujun
  • 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:

let f = File::open("hello.txt").expect("Failed to open hello.txt");

Description of the problem:

let f = File::open("hello.txt").expect("Failed to open hello.txt");

"expect failed to open hello.txt" confused me. Are we expecting a failure?

Suggested fix:

let f = File::open("hello.txt").expect("Succeed to open hello.txt");

Or explain this API design more.

Same confused from stackoverflow: https://stackoverflow.com/questions/66362625/why-is-rusts-expect-called-expect

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