Struct handy_async::error::AsyncError
[−]
[src]
pub struct AsyncError<T, E> { /* fields omitted */ }
The error type for asynchronous operations.
This contains an actual error value and the state that caused the error.
Examples
use std::io::{empty, ErrorKind}; use handy_async::io::AsyncRead; use handy_async::error::AsyncError; use futures::Future; // Trying to read any bytes from `empty()` stream will result in an `UnexpectedEof` error. let e: AsyncError<_, _> = empty().async_read_non_empty([0]).wait().err().unwrap(); assert_eq!(e.error_ref().kind(), ErrorKind::UnexpectedEof);
Methods
impl<T, E> AsyncError<T, E> where
E: Error,
[src]
E: Error,
fn new(state: T, error: E) -> Self
Makes a new error instance.
fn state_ref(&self) -> &T
Gets the immutable reference of the state of this AsyncError
.
fn state_muf(&mut self) -> &mut T
Gets the mutable reference of the state of this AsyncError
.
fn into_state(self) -> T
Converts this AsyncError
into the underlying state T
.
fn error_ref(&self) -> &E
Gets the immutable reference of the actual error of this AsyncError
.
fn error_mut(&mut self) -> &mut E
Gets the mutable reference of the actual error of this AsyncError
.
fn into_error(self) -> E
Converts this AsyncError
into the underlying error E
.
fn unwrap(self) -> (T, E)
Unwraps this AsyncError
, returing the underlying state and error as (T, E)
.
fn map_state<F, U>(self, f: F) -> AsyncError<U, E> where
F: FnOnce(T) -> U,
F: FnOnce(T) -> U,
Maps a AsyncError<T, E>
to AsyncError<U, E>
by
applying a function F
to the contained state.
Examples
use std::io::{Error, ErrorKind}; use handy_async::error::AsyncError; let error = AsyncError::new("dummy_state", Error::new(ErrorKind::Other, "")); assert_eq!(error.state_ref(), &"dummy_state"); let error = error.map_state(|s| s.len()); assert_eq!(error.state_ref(), &11);
Trait Implementations
impl<T, E> Debug for AsyncError<T, E> where
E: Error,
[src]
E: Error,
impl<T, E> Display for AsyncError<T, E> where
E: Error,
[src]
E: Error,
impl<T, E> Error for AsyncError<T, E> where
E: Error,
[src]
E: Error,