1pub trait TryClone : Sized {
5 type Error;
7
8 fn try_clone(&self) -> Result<Self, Self::Error>;
10
11 #[inline]
13 fn try_clone_from(&mut self, source: &Self) -> Result<(), Self::Error> {
14 Ok(*self = source.try_clone()?)
15 }
16}
17
18impl<T: Clone> TryClone for T {
19 type Error = crate::Infallible;
20
21 #[inline]
22 fn try_clone(&self) -> Result<Self, Self::Error> {
23 Ok(self.clone())
24 }
25
26 #[inline]
27 fn try_clone_from(&mut self, source: &Self) -> Result<(), Self::Error> {
28 Ok(self.clone_from(source))
29 }
30}