Struct interprocess::error::ConversionError

source ·
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>

source

pub fn from_source(source: S) -> Self

Constructs an error value without an OS cause and with default contents for the “details” field.

source

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.

source

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>

source

pub fn from_source_and_details(source: S, details: E) -> Self

Constructs an error value without an OS cause.

source

pub fn from_cause_and_details(cause: Error, details: E) -> Self

Constructs an error value that doesn’t return input ownership.

source

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.

source

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>

source

pub fn to_io_error(&self) -> Error

Boxes the error into an io::Error.

Trait Implementations§

source§

impl<S: Debug, E: Debug> Debug for ConversionError<S, E>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<S, E: Default> Default for ConversionError<S, E>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<S, E: Display> Display for ConversionError<S, E>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<S: Debug, E: Error + 'static> Error for ConversionError<S, E>

source§

fn source(&self) -> Option<&(dyn Error + 'static)>

The lower-level source of this error, if any. Read more
1.0.0 · source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type based access to context intended for error reports. Read more
source§

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.

source§

fn from(e: ConversionError<S, E>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<S, E> Freeze for ConversionError<S, E>
where E: Freeze, S: Freeze,

§

impl<S, E = NoDetails> !RefUnwindSafe for ConversionError<S, E>

§

impl<S, E> Send for ConversionError<S, E>
where E: Send, S: Send,

§

impl<S, E> Sync for ConversionError<S, E>
where E: Sync, S: Sync,

§

impl<S, E> Unpin for ConversionError<S, E>
where E: Unpin, S: Unpin,

§

impl<S, E = NoDetails> !UnwindSafe for ConversionError<S, E>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.