erased_serde/
map.rs

1pub(crate) trait ResultExt<T, E> {
2    unsafe fn unsafe_map<U>(self, op: unsafe fn(T) -> U) -> Result<U, E>;
3}
4
5impl<T, E> ResultExt<T, E> for Result<T, E> {
6    unsafe fn unsafe_map<U>(self, op: unsafe fn(T) -> U) -> Result<U, E> {
7        match self {
8            Ok(t) => Ok(unsafe { op(t) }),
9            Err(e) => Err(e),
10        }
11    }
12}
13
14pub(crate) trait OptionExt<T> {
15    unsafe fn unsafe_map<U>(self, op: unsafe fn(T) -> U) -> Option<U>;
16}
17
18impl<T> OptionExt<T> for Option<T> {
19    unsafe fn unsafe_map<U>(self, op: unsafe fn(T) -> U) -> Option<U> {
20        match self {
21            Some(t) => Some(unsafe { op(t) }),
22            None => None,
23        }
24    }
25}