pub type ExnResult<T = (), E = Untyped> = Result<T, Exn<E>>;Expand description
A result with an Exn<E> error, defaulting to unit success and an erased error type.
ExnResult<T> uses the same exn::Untyped marker as bare Exn. Specify E to retain a
concrete error type; ExnMessageResult is the shorthand for message contexts. All standard result operations and
ResultExt methods remain available. Use ResultExt::or_erased() for callbacks accepting
different error types, and ? to propagate exceptions into Error at API boundaries.
use gix_error::{message, ErrorExt, ExnMessageResult, ExnResult, ResultExt};
fn parse_count(input: &str) -> ExnMessageResult<u64> {
input.parse::<u64>().or_raise(|| message("could not parse count"))
}
fn process(callback: impl FnOnce() -> ExnResult<u64>) -> ExnMessageResult {
let count = callback().or_raise(|| message("callback failed"))?;
assert_eq!(count, 42, "the callback supplies the parsed count");
Ok(())
}
let done: ExnResult = process(|| parse_count("42").or_erased()).or_erased();
done?;
let io: ExnResult<(), std::io::Error> =
Err(std::io::Error::from(std::io::ErrorKind::NotFound).raise());
assert_eq!(io.expect_err("the I/O operation failed").error().kind(), std::io::ErrorKind::NotFound);Aliased Type§
pub enum ExnResult<T = (), E = Untyped> {
Ok(T),
Err(Exn<E>),
}