diff --git a/crates/core/src/alloc/try_clone.rs b/crates/core/src/alloc/try_clone.rs index c59b62380b5e..85837f94c778 100644 --- a/crates/core/src/alloc/try_clone.rs +++ b/crates/core/src/alloc/try_clone.rs @@ -1,5 +1,6 @@ use crate::error::OutOfMemory; use core::mem; +use std_alloc::sync::Arc; /// A trait for values that can be cloned, but contain owned, heap-allocated /// values whose allocations may fail during cloning. @@ -39,6 +40,40 @@ where } } +impl TryClone for Result +where + T: TryClone, + E: TryClone, +{ + #[inline] + fn try_clone(&self) -> Result { + match self { + Ok(x) => Ok(Ok(x.try_clone()?)), + Err(e) => Ok(Err(e.try_clone()?)), + } + } +} + +impl TryClone for Option +where + T: TryClone, +{ + #[inline] + fn try_clone(&self) -> Result { + match self { + Some(x) => Ok(Some(x.try_clone()?)), + None => Ok(None), + } + } +} + +impl TryClone for Arc { + #[inline] + fn try_clone(&self) -> Result { + Ok(self.clone()) + } +} + macro_rules! impl_try_clone_via_clone { ( $( $ty:ty ),* $(,)? ) => { $(