pub struct ValueError<T> { /* private fields */ }
Expand description
Helper type that is core::error::Error
and wraps a value and an error message.
This can be used to return an object as part of an Err
and is used for fallible conversions.
Implementations§
Source§impl<T> ValueError<T>
impl<T> ValueError<T>
Sourcepub fn new(value: T, msg: impl Display) -> Self
pub fn new(value: T, msg: impl Display) -> Self
Creates a new error with the given value and error message.
Sourcepub fn new_static(value: T, msg: &'static str) -> Self
pub fn new_static(value: T, msg: &'static str) -> Self
Creates a new error with a static error message.
Sourcepub fn convert<U>(self) -> ValueError<U>where
U: From<T>,
pub fn convert<U>(self) -> ValueError<U>where
U: From<T>,
Converts the value to the given alternative that is From<T>
.
Sourcepub fn map<U>(self, f: impl FnOnce(T) -> U) -> ValueError<U>
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> ValueError<U>
Maps the error’s value with the given closure.
Sourcepub fn into_value(self) -> T
pub fn into_value(self) -> T
Consumes the type and returns the underlying value.
Trait Implementations§
Source§impl<T: Debug> Debug for ValueError<T>
impl<T: Debug> Debug for ValueError<T>
Source§impl<T> Display for ValueError<T>
impl<T> Display for ValueError<T>
Source§impl<T> Error for ValueError<T>
impl<T> Error for ValueError<T>
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Auto Trait Implementations§
impl<T> Freeze for ValueError<T>
impl<T> RefUnwindSafe for ValueError<T>where
T: RefUnwindSafe,
impl<T> Send for ValueError<T>where
T: Send,
impl<T> Sync for ValueError<T>where
T: Sync,
impl<T> Unpin for ValueError<T>
impl<T> UnwindSafe for ValueError<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more