Skip to content

Commit

Permalink
Add map function to Error
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 committed Mar 7, 2018
1 parent 0c7e380 commit 109aad9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,17 @@ where
}
}

impl<E> Error<E> {
/// Maps an `Error<E>` to `Error<T>` by applying a function to a contained
/// `Error::Other` value, leaving an `Error::WouldBlock` value untouched.
pub fn map<T, F>(self, op: F) -> Error<T> where F: FnOnce(E) -> T {
match self {
Error::Other(e) => Error::Other(op(e)),
Error::WouldBlock => Error::WouldBlock,
}
}
}

/// Await operation (*won't work until the language gains support for
/// generators*)
///
Expand Down

0 comments on commit 109aad9

Please sign in to comment.