| 1 |
//! this module implements try clone for primitive rust types |
| 2 |
|
| 3 |
use super::TryClone; |
| 4 |
use crate::TryReserveError; |
| 5 |
|
| 6 |
macro_rules! impl_try_clone { |
| 7 |
($($e: ty),*) => { |
| 8 |
$(impl TryClone for $e { |
| 9 |
#[inline(always)] |
| 10 |
fn try_clone(&self) -> Result<Self, TryReserveError> |
| 11 |
where |
| 12 |
Self: core::marker::Sized, |
| 13 |
{ |
| 14 |
Ok(*self) |
| 15 |
} |
| 16 |
} |
| 17 |
)* |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
impl_try_clone!(u8, u16, u32, u64, i8, i16, i32, i64, usize, isize, bool); |
| 22 |
|
| 23 |
impl<T: TryClone> TryClone for Option<T> { |
| 24 |
#[inline] |
| 25 |
fn try_clone(&self) -> Result<Self, TryReserveError> { |
| 26 |
Ok(match self { |
| 27 |
Some(t) => Some(t.try_clone()?), |
| 28 |
None => None, |
| 29 |
}) |
| 30 |
} |
| 31 |
} |
| 32 |
// impl<T: Copy> TryClone for T { |
| 33 |
// fn try_clone(&self) -> Result<Self, TryReserveError> |
| 34 |
// where |
| 35 |
// Self: core::marker::Sized, |
| 36 |
// { |
| 37 |
// Ok(*self) |
| 38 |
// } |
| 39 |
// } |