Skip to content

Commit

Permalink
Implements StableResult::map() and StableResult::map_err().
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Oct 1, 2023
1 parent ae16614 commit cf485c6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ impl<T: Debug, E: Debug> StableResult<T, E> {
}
}

/// Maps ok values, leaving error values untouched
pub fn map<U, O: FnOnce(T) -> U>(self, op: O) -> StableResult<U, E> {
match self {
Self::Ok(value) => StableResult::<U, E>::Ok(op(value)),
Self::Err(error) => StableResult::<U, E>::Err(error),
}
}

/// Maps error values, leaving ok values untouched
pub fn map_err<F, O: FnOnce(E) -> F>(self, op: O) -> StableResult<T, F> {
match self {
Self::Ok(value) => StableResult::<T, F>::Ok(value),
Self::Err(error) => StableResult::<T, F>::Err(op(error)),
}
}

#[cfg_attr(
any(
not(feature = "jit"),
Expand Down

0 comments on commit cf485c6

Please sign in to comment.