-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-error-handlingArea: Error handlingArea: Error handlingA-result-optionArea: Result and Option combinatorsArea: Result and Option combinatorsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.PG-error-handlingProject group: Error handling (https://github.com/rust-lang/project-error-handling)Project 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.Relevant to the library API team, which will review and decide on the PR/issue.
Description
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
- fixes a papercut with error modeling and error handling
- api requires minimal consideration since it already has a stable counterpart (as well as unstable siblings:
unwrap_none
/expect_none
Tracking issue for Option::expect_none(msg) and unwrap_none() #62633)
cons
- name looks like
error
, might cause confusion - not extremely common use case? (haven't checked discussion on
unwrap_none
yet)
Metadata
Metadata
Assignees
Labels
A-error-handlingArea: Error handlingArea: Error handlingA-result-optionArea: Result and Option combinatorsArea: Result and Option combinatorsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.PG-error-handlingProject group: Error handling (https://github.com/rust-lang/project-error-handling)Project 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.Relevant to the library API team, which will review and decide on the PR/issue.