Skip to content

API: Add err_or and err_or_else to Option #80190

Closed
@LunarLambda

Description

@LunarLambda

sometimes, particularly when interfacing with C libraries which provide their own errno-like API (GetLastError, SDL_GetError, etc), Rust bindings may opt to return Option<ErrorType> to model the absence of an error.

This could then be 'upgraded' to a Result<T, E>, in a manner similar to ok_or:

fn example() -> Result<(), SomeError> {
    get_some_error().err_or(())
}

pros

cons

  • name looks like error, might cause confusion
  • not extremely common use case? (haven't checked discussion on unwrap_none yet)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-error-handlingArea: Error handlingA-result-optionArea: Result and Option combinatorsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.PG-error-handlingProject group: Error handling (https://github.com/rust-lang/project-error-handling)T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions