#[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
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>
impl<A> PickError<A>
Sourcepub fn factor(self) -> Result<A, PickError>
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: StdError> Error for PickError<A>
impl<A: StdError> Error for PickError<A>
1.30.0 · 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
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> 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
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>
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>
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