Skip to content

Commit

Permalink
Add LocalResult<T>::map_result_unique()
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomtir committed Feb 28, 2024
1 parent 130bf14 commit b9f133b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/offset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ impl<T> LocalResult<T> {
LocalResult::Ambiguous(min, max) => LocalResult::Ambiguous(f(min), f(max)),
}
}

/// Maps a `LocalResult<T>` into `Result<T, Error>`.
///
/// Returns [`Error::InvalidArgument`] if the conversion result not unique.
pub fn map_result_unique(self) -> Result<T, Error> {
match self {
LocalResult::Single(t) => Ok(t),
_ => Err(Error::InvalidArgument),
}
}
}

impl<T: fmt::Debug> LocalResult<T> {
Expand Down

0 comments on commit b9f133b

Please sign in to comment.