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. Use these aliases when callers
need typed exceptions or exception-tree operations; other public and private code uses Result.
All standard result operations and ResultExt methods remain available. Use ResultExt::or_erased() for
callbacks requiring erased exceptions, and ? to propagate exceptions into Error.
Preserve this alias in public signatures that already expose a concrete error type.
use gix_error::{ErrorExt, ExnResult};
fn parse_count(input: &str) -> ExnResult<u64, std::num::ParseIntError> {
input.parse::<u64>().map_err(ErrorExt::raise_typed)
}
let error = parse_count("not a count").expect_err("the count contains letters");
assert_eq!(
error.error().kind(),
&std::num::IntErrorKind::InvalidDigit,
"callers can inspect the concrete error without downcasting"
);Aliased Type§
pub enum ExnResult<T = (), E = Untyped> {
Ok(T),
Err(Exn<E>),
}Variants§
Trait Implementations§
Source§impl<T, E> ResultExt for ExnResult<T, E>
impl<T, E> ResultExt for ExnResult<T, E>
Source§fn or_raise_typed<A, F>(self, err: F) -> ExnResult<Self::Success, A>
fn or_raise_typed<A, F>(self, err: F) -> ExnResult<Self::Success, A>
Like
Self::or_raise(), retaining the context’s type in an exception.Source§fn or_erased(self) -> ExnResult<Self::Success>
fn or_erased(self) -> ExnResult<Self::Success>
Raise a new exception on the
Exn inside the Result, but erase its type.
Errors implementing std::error::Error use ErrorExt::raise_erased. Read more