Taking the example:
use terrors::OneOf;
struct Timeout;
struct AllocationFailure;
fn allocate_box() -> Result<Box<u8>, OneOf<(AllocationFailure,)>> {
Err(AllocationFailure.into())
}
fn send() -> Result<(), OneOf<(Timeout,)>> {
Err(Timeout.into())
}
fn allocate_and_send() -> Result<(), OneOf<(AllocationFailure, Timeout)>> {
let boxed_byte: Box<u8> = allocate_box().map_err(OneOf::broaden)?;
send().map_err(OneOf::broaden)?;
Ok(())
}
// ...
Instead of using allocate_box().map_err(OneOf::broaden)?, we could implement Into for any subset of a OneOf so this can be simplified to just allocate_box()?, and the ? operator will implicitly broaden the error.
Taking the example:
Instead of using
allocate_box().map_err(OneOf::broaden)?, we could implementIntofor any subset of aOneOfso this can be simplified to justallocate_box()?, and the?operator will implicitly broaden the error.