pub struct ConversionError<S, E = NoDetails> {
pub details: E,
pub cause: Option<Error>,
pub source: Option<S>,
}
Expand description
General error type for fallible constructors.
In Interprocess, many types feature conversions to and from handles/file descriptors and types from the standard library. Many of those conversions are fallible because the semantic mapping between the source and destination types is not always 1:1, with various invariants that need to be upheld and which are always queried for. With async types, this is further complicated: runtimes typically need to register OS objects in their polling/completion infrastructure to use them asynchronously.
All those conversion have one thing in common: they consume ownership of one object and return
ownership of its new form. If the conversion fails, it would be invaluably useful in some cases
to return ownership of the original object back to the caller, so that it could use it in some
other way. The source
field allows for that, but also reserves the callee’s freedom not to do
so. (Hey, it’s not like I wanted it to be like this, Tokio just doesn’t have .try_clone()
and returns io::Error
. Oh well, unwrapping’s always an option.)
Many (but not all) of those conversions also have an OS error they can attribute the failure to.
Additionally, some conversions have an additional “details” error field that contains extra infromation about the error. That is typically an enumeration that specifies which stage of the conversion the OS error happened on.
Fields§
§details: E
Extra information about the error.
cause: Option<Error>
The underlying OS error, if any.
source: Option<S>
Ownership of the input of the conversion.
Implementations§
Source§impl<S, E: Default> ConversionError<S, E>
impl<S, E: Default> ConversionError<S, E>
Sourcepub fn from_source(source: S) -> Self
pub fn from_source(source: S) -> Self
Constructs an error value without an OS cause and with default contents for the “details” field.
Sourcepub fn from_cause(cause: Error) -> Self
pub fn from_cause(cause: Error) -> Self
Constructs an error value that doesn’t return input ownership, with default contents for the “details” field and an OS cause.
Sourcepub fn from_source_and_cause(source: S, cause: Error) -> Self
pub fn from_source_and_cause(source: S, cause: Error) -> Self
Constructs an error value from a given OS cause, filling the “details” field with its default value.
Source§impl<S, E> ConversionError<S, E>
impl<S, E> ConversionError<S, E>
Sourcepub fn from_source_and_details(source: S, details: E) -> Self
pub fn from_source_and_details(source: S, details: E) -> Self
Constructs an error value without an OS cause.
Sourcepub fn from_cause_and_details(cause: Error, details: E) -> Self
pub fn from_cause_and_details(cause: Error, details: E) -> Self
Constructs an error value that doesn’t return input ownership.
Sourcepub fn map_source<Sb>(self, f: impl FnOnce(S) -> Sb) -> ConversionError<Sb, E>
pub fn map_source<Sb>(self, f: impl FnOnce(S) -> Sb) -> ConversionError<Sb, E>
Maps the type with which ownership over the input is returned using the given closure.
This utility is mostly used in the crate’s internals.
Sourcepub fn try_map_source<Sb>(
self,
f: impl FnOnce(S) -> Option<Sb>,
) -> ConversionError<Sb, E>
pub fn try_map_source<Sb>( self, f: impl FnOnce(S) -> Option<Sb>, ) -> ConversionError<Sb, E>
Maps the type with which ownership over the input is returned using the given closure, also allowing it to drop the ownership.
This utility is mostly used in the crate’s internals.
Source§impl<S, E: Display> ConversionError<S, E>
impl<S, E: Display> ConversionError<S, E>
Sourcepub fn to_io_error(&self) -> Error
pub fn to_io_error(&self) -> Error
Boxes the error into an io::Error
.
Trait Implementations§
Source§impl<S, E: Default> Default for ConversionError<S, E>
impl<S, E: Default> Default for ConversionError<S, E>
Source§impl<S, E: Display> Display for ConversionError<S, E>
impl<S, E: Display> Display for ConversionError<S, E>
Source§impl<S: Debug, E: Error + 'static> Error for ConversionError<S, E>
impl<S: Debug, E: Error + 'static> Error for ConversionError<S, E>
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl<S, E: Display> From<ConversionError<S, E>> for Error
impl<S, E: Display> From<ConversionError<S, E>> for Error
Boxes the error into an io::Error
, dropping the retained file descriptor in the process.