PickError

Enum PickError 

Source
#[non_exhaustive]
pub enum PickError<A = Infallible> { IO(Error), Disconnected, UserInterrupted, NotInteractive, Aborted(A), }
Expand description

An error which may occur while running the picker interactively.

This is marked non-exhaustive since more variants may be added in the future. It is recommended to handle the errors that are relevant to your application and propagate any remaining errors as an io::Error.

§Type parameter for Aborted variant

The PickError::Aborted variant can be used by the application to propagate errors to the picker; the application-defined error type is the type parameter A. By default, A = ! which means this type of error will never occur and can be ignored during pattern matching.

This library will never generate an abort error directly. In order to pass errors downstream to the picker, the application can define an abort error type using the EventSource::AbortErr associated type. This associated type is the same as the type parameter here when used in Picker::pick_with_io.

§Relationship to io::Error

This error type with the default type parameter is (in spirit) an io::Error, but with more precise variants not present in the default io::Error. For convenience and (partial) backwards compatibility, there is a From<PickError> for io::Error implementation; this propagates the underlying IO error and converts any other error message to an io::Error using io::Error::other.

There is also a From<PickError<io::Error>> for io::Error to handle the common use-case that the only error type which may occur during standard operation of your application is an IO error; in this case, the conversion maps both the Aborted(io::Error) and IO(io::Error) versions directly to an io::Error.

Any other abort error type A requires manual handling. The PickError::factor method can be used to unwind non-aborted variants into an io::Error and extract the error present in the Aborted variant.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

IO(Error)

A read or write resulted in an IO error.

§

Disconnected

A necessary channel disconnected while the picker was still running.

§

UserInterrupted

The picker quit at the user’s request.

§

NotInteractive

The picker could not be started since the writer is not interactive.

§

Aborted(A)

The picker was aborted because of an upstream error.

Implementations§

Source§

impl<A> PickError<A>

Source

pub fn factor(self) -> Result<A, PickError>

Convert a PickError<A> into either an Ok(A) or Err(PickError<!>), for convenience of error propogation.

§Example

Use factor to simplify processing of custom PickError<A>s when you mainly care about your application error.

use std::{fmt::Display, io};

// Even though `PickError<A>` need not satisfy `Into<io::Error>`, `PickError<!>`
// always does.
fn print_or_propogate<A: Display>(pick_err: PickError<A>) -> Result<(), io::Error> {
    let app_err = pick_err.factor()?;
    eprintln!("{app_err}");
    Ok(())
}

Trait Implementations§

Source§

impl<A: Debug> Debug for PickError<A>

Source§

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

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

impl<A: Display> Display for PickError<A>

Source§

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

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

impl<A: StdError> Error for PickError<A>

1.30.0 · 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<A> From<Error> for PickError<A>

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<PickError<Error>> for Error

Source§

fn from(err: PickError<Error>) -> Self

Converts to this type from the input type.
Source§

impl From<PickError> for Error

Source§

fn from(err: PickError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<A> Freeze for PickError<A>
where A: Freeze,

§

impl<A = Infallible> !RefUnwindSafe for PickError<A>

§

impl<A> Send for PickError<A>
where A: Send,

§

impl<A> Sync for PickError<A>
where A: Sync,

§

impl<A> Unpin for PickError<A>
where A: Unpin,

§

impl<A = Infallible> !UnwindSafe for PickError<A>

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

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.