Trait ResultExt
pub trait ResultExt<T, E> {
// Required methods
fn into_error<U>(self) -> Result<T, U> ⓘ
where U: Source,
E: Error + Send + Sync + 'static;
fn into_trace<U, R>(self, trace: R) -> Result<T, U> ⓘ
where U: Source,
R: Debug + Display + Send + Sync + 'static,
E: Error + Send + Sync + 'static;
fn into_with_trace<U, R, F>(self, f: F) -> Result<T, U> ⓘ
where U: Source,
R: Debug + Display + Send + Sync + 'static,
F: FnOnce() -> R,
E: Error + Send + Sync + 'static;
fn trace<R>(self, trace: R) -> Result<T, E> ⓘ
where R: Debug + Display + Send + Sync + 'static,
E: Trace;
fn with_trace<R, F>(self, f: F) -> Result<T, E> ⓘ
where R: Debug + Display + Send + Sync + 'static,
F: FnOnce() -> R,
E: Trace;
fn always_ok(self) -> T
where E: Never;
}
Available on crate feature
dep_rkyv
only.Expand description
Helper methods for Result
s.
Required Methods§
fn into_error<U>(self) -> Result<T, U> ⓘ
fn into_error<U>(self) -> Result<T, U> ⓘ
Returns a Result
with this error type converted to U
.
§Example
use rancor::{Failure, ResultExt as _};
let result = "1_000".parse::<i32>().into_error::<Failure>();
fn into_trace<U, R>(self, trace: R) -> Result<T, U> ⓘ
fn into_trace<U, R>(self, trace: R) -> Result<T, U> ⓘ
Returns a Result
with this error type converted to U
and with an
additional trace
message added.
§Example
use rancor::{BoxedError, ResultExt as _};
let result = "1_000"
.parse::<i32>()
.into_trace::<BoxedError, _>("while parsing 1_000");
fn into_with_trace<U, R, F>(self, f: F) -> Result<T, U> ⓘ
fn into_with_trace<U, R, F>(self, f: F) -> Result<T, U> ⓘ
Returns a Result
with this error type converted to U
and with an
additional trace message added by evaluating the given function f
. The
function is evaluated only if an error occurred.
§Example
use rancor::{BoxedError, ResultExt as _};
let input = "1_000";
let result =
input
.parse::<i32>()
.into_with_trace::<BoxedError, _, _>(|| {
format!("while parsing {input}")
});
fn trace<R>(self, trace: R) -> Result<T, E> ⓘ
fn trace<R>(self, trace: R) -> Result<T, E> ⓘ
Adds an additional trace
message to the error value of this type.
§Example
use rancor::{BoxedError, ResultExt as _};
let result = "1_000"
.parse::<i32>()
.into_error::<BoxedError>()
.trace("while parsing 1_000");
fn with_trace<R, F>(self, f: F) -> Result<T, E> ⓘ
fn with_trace<R, F>(self, f: F) -> Result<T, E> ⓘ
Adds an additional trace message to the error value of this type by
evaluating the given function f
. The function is evaluated only if an
error occurred.
§Example
use rancor::{BoxedError, ResultExt as _};
let input = "1_000";
let result = input
.parse::<i32>()
.into_error::<BoxedError>()
.with_trace(|| format!("while parsing {input}"));
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.