interprocess::error

Struct 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)>

Returns 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>,

Source§

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>,

Source§

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.