pub trait ResultExt<T> {
// Required methods
fn or_user_err(self, advice: &'static [&'static str]) -> Result<T, Error>;
fn wrap_user_err<S: Into<Cow<'static, str>> + 'static>(
self,
message: S,
advice: &'static [&'static str],
) -> Result<T, Error>;
fn or_system_err(self, advice: &'static [&'static str]) -> Result<T, Error>;
fn wrap_system_err<S: Into<Cow<'static, str>> + 'static>(
self,
message: S,
advice: &'static [&'static str],
) -> Result<T, Error>;
fn map_err_as_user(
self,
advice: &'static [&'static str],
) -> Result<T, Error>;
fn wrap_err_as_user<S: Into<Cow<'static, str>> + 'static>(
self,
message: S,
advice: &'static [&'static str],
) -> Result<T, Error>;
fn map_err_as_system(
self,
advice: &'static [&'static str],
) -> Result<T, Error>;
fn wrap_err_as_system<S: Into<Cow<'static, str>> + 'static>(
self,
message: S,
advice: &'static [&'static str],
) -> Result<T, Error>;
}Expand description
Extension trait for Result to convert errors into user-friendly or
system-friendly Error types.
§Examples
use human_errors::ResultExt;
// Converts any error into a user-caused error with the provided advice.
"0.not a number".parse::<i32>()
.map_err_as_user(&["Please provide a valid integer input."]);
// Converts any error into a system-caused error with the provided advice.
"0.not a number".parse::<i32>()
.map_err_as_system(&["Please check your system configuration."]);
// Wraps any error into a user-caused error with a custom message and advice.
"0.not a number".parse::<i32>()
.wrap_err_as_user(
"Failed to parse the provided input as an integer.",
&["Please provide a valid integer input."],
);
// Wraps any error into a system-caused error with a custom message and advice.
"0.not a number".parse::<i32>()
.wrap_err_as_system(
"Failed to parse the provided input as an integer.",
&["Please check your system configuration."],
);Required Methods§
Sourcefn or_user_err(self, advice: &'static [&'static str]) -> Result<T, Error>
fn or_user_err(self, advice: &'static [&'static str]) -> Result<T, Error>
Converts a Result<T, E> into a Result<T, Error>, wrapping any
error in a user-facing error with the provided advice.
§Examples
use human_errors::ResultExt;
"0.not a number".parse::<i32>()
.or_user_err(&["Please provide a valid integer input."]);Sourcefn wrap_user_err<S: Into<Cow<'static, str>> + 'static>(
self,
message: S,
advice: &'static [&'static str],
) -> Result<T, Error>
fn wrap_user_err<S: Into<Cow<'static, str>> + 'static>( self, message: S, advice: &'static [&'static str], ) -> Result<T, Error>
Converts a Result<T, E> into a Result<T, Error>, wrapping any
error in a user-facing error with the provided description and advice.
§Examples
use human_errors::ResultExt;
"0.not a number".parse::<i32>()
.wrap_user_err(
"Failed to parse the provided input as an integer.",
&["Please provide a valid integer input."],
);Sourcefn or_system_err(self, advice: &'static [&'static str]) -> Result<T, Error>
fn or_system_err(self, advice: &'static [&'static str]) -> Result<T, Error>
Converts a Result<T, E> into a Result<T, Error>, wrapping any
error in a system-facing error with the provided advice.
§Examples
use human_errors::ResultExt;
"0.not a number".parse::<i32>()
.or_system_err(&["Please report this issue to the dev team."]);Sourcefn wrap_system_err<S: Into<Cow<'static, str>> + 'static>(
self,
message: S,
advice: &'static [&'static str],
) -> Result<T, Error>
fn wrap_system_err<S: Into<Cow<'static, str>> + 'static>( self, message: S, advice: &'static [&'static str], ) -> Result<T, Error>
Converts a Result<T, E> into a Result<T, Error>, wrapping any
error in a system-facing error with the provided description and advice.
§Examples
use human_errors::ResultExt;
"0.not a number".parse::<i32>()
.wrap_system_err(
"Failed to parse the provided input as an integer.",
&["Please report this issue to the dev team."],
);Sourcefn map_err_as_user(self, advice: &'static [&'static str]) -> Result<T, Error>
👎Deprecated since 0.2.3: We are updating the interface to match the Rust stdlib style. Please use or_user_err method instead.
fn map_err_as_user(self, advice: &'static [&'static str]) -> Result<T, Error>
or_user_err method instead.Converts a Result<T, E> into a Result<T, Error>, wrapping any
error in a user-facing error with the provided advice.
§Examples
use human_errors::ResultExt;
"0.not a number".parse::<i32>()
.map_err_as_user(&["Please provide a valid integer input."]);Sourcefn wrap_err_as_user<S: Into<Cow<'static, str>> + 'static>(
self,
message: S,
advice: &'static [&'static str],
) -> Result<T, Error>
👎Deprecated since 0.2.3: We are updating the interface to match the Rust stdlib style. Please use wrap_user_err method instead.
fn wrap_err_as_user<S: Into<Cow<'static, str>> + 'static>( self, message: S, advice: &'static [&'static str], ) -> Result<T, Error>
wrap_user_err method instead.Converts a Result<T, E> into a Result<T, Error>, wrapping any
error in a user-facing error with the provided description and advice.
§Examples
use human_errors::ResultExt;
"0.not a number".parse::<i32>()
.wrap_err_as_user(
"Failed to parse the provided input as an integer.",
&["Please provide a valid integer input."],
);Sourcefn map_err_as_system(self, advice: &'static [&'static str]) -> Result<T, Error>
👎Deprecated since 0.2.3: We are updating the interface to match the Rust stdlib style. Please use or_system_err method instead.
fn map_err_as_system(self, advice: &'static [&'static str]) -> Result<T, Error>
or_system_err method instead.Converts a Result<T, E> into a Result<T, Error>, wrapping any
error in a system-facing error with the provided advice.
§Examples
use human_errors::ResultExt;
"0.not a number".parse::<i32>()
.map_err_as_system(&["Please report this issue to the dev team."]);Sourcefn wrap_err_as_system<S: Into<Cow<'static, str>> + 'static>(
self,
message: S,
advice: &'static [&'static str],
) -> Result<T, Error>
👎Deprecated since 0.2.3: We are updating the interface to match the Rust stdlib style. Please use wrap_system_err method instead.
fn wrap_err_as_system<S: Into<Cow<'static, str>> + 'static>( self, message: S, advice: &'static [&'static str], ) -> Result<T, Error>
wrap_system_err method instead.Converts a Result<T, E> into a Result<T, Error>, wrapping any
error in a system-facing error with the provided description and advice.
§Examples
use human_errors::ResultExt;
"0.not a number".parse::<i32>()
.wrap_err_as_system(
"Failed to parse the provided input as an integer.",
&["Please report this issue to the dev team."],
);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.
Implementations on Foreign Types§
Source§impl<T, E> ResultExt<T> for Result<T, E>
impl<T, E> ResultExt<T> for Result<T, E>
fn or_user_err(self, advice: &'static [&'static str]) -> Result<T, Error>
fn wrap_user_err<S: Into<Cow<'static, str>> + 'static>( self, message: S, advice: &'static [&'static str], ) -> Result<T, Error>
fn or_system_err(self, advice: &'static [&'static str]) -> Result<T, Error>
fn wrap_system_err<S: Into<Cow<'static, str>> + 'static>( self, message: S, advice: &'static [&'static str], ) -> Result<T, Error>
Source§fn map_err_as_user(self, advice: &'static [&'static str]) -> Result<T, Error>
fn map_err_as_user(self, advice: &'static [&'static str]) -> Result<T, Error>
or_user_err method instead.Source§fn wrap_err_as_user<S: Into<Cow<'static, str>> + 'static>(
self,
message: S,
advice: &'static [&'static str],
) -> Result<T, Error>
fn wrap_err_as_user<S: Into<Cow<'static, str>> + 'static>( self, message: S, advice: &'static [&'static str], ) -> Result<T, Error>
wrap_user_err method instead.