Closed
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)