diff options
Diffstat (limited to 'vendor/erased-serde/src/map.rs')
-rw-r--r-- | vendor/erased-serde/src/map.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/vendor/erased-serde/src/map.rs b/vendor/erased-serde/src/map.rs new file mode 100644 index 000000000..c670805e3 --- /dev/null +++ b/vendor/erased-serde/src/map.rs @@ -0,0 +1,25 @@ +pub(crate) trait ResultExt<T, E> { + unsafe fn unsafe_map<U>(self, op: unsafe fn(T) -> U) -> Result<U, E>; +} + +impl<T, E> ResultExt<T, E> for Result<T, E> { + unsafe fn unsafe_map<U>(self, op: unsafe fn(T) -> U) -> Result<U, E> { + match self { + Ok(t) => Ok(unsafe { op(t) }), + Err(e) => Err(e), + } + } +} + +pub(crate) trait OptionExt<T> { + unsafe fn unsafe_map<U>(self, op: unsafe fn(T) -> U) -> Option<U>; +} + +impl<T> OptionExt<T> for Option<T> { + unsafe fn unsafe_map<U>(self, op: unsafe fn(T) -> U) -> Option<U> { + match self { + Some(t) => Some(unsafe { op(t) }), + None => None, + } + } +} |