#![cfg_attr(
feature = "blanket-impl",
feature(auto_traits, negative_impls, min_specialization)
)]
#![cfg_attr(
all(feature = "alloc", feature = "nightly"),
feature(allocator_api, clone_from_ref)
)]
#![cfg_attr(feature = "doc-cfg", feature(doc_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
pub trait TryClone: Sized {
type Error;
fn try_clone(&self) -> Result<Self, Self::Error>;
fn try_clone_from(&mut self, source: &Self) -> Result<(), Self::Error> {
*self = source.try_clone()?;
Ok(())
}
}
pub trait TryCloneToOwned: Sized {
type Owned;
type Error;
fn try_clone_to_owned(&self) -> Result<Self::Owned, Self::Error>;
}
pub fn try_clone<T: TryClone>(o: &T) -> Result<T, T::Error> {
o.try_clone()
}
pub fn try_clone_to_owned<T: TryCloneToOwned>(o: &T) -> Result<T::Owned, T::Error> {
o.try_clone_to_owned()
}
#[cfg(feature = "blanket-impl")]
use ::core::convert::Infallible;
#[cfg(feature = "blanket-impl")]
include!("blanket_impl.rs");
#[cfg(feature = "blanket-impl")]
impl<T: Clone + ForwardTryCloneToClone> TryClone for T {
type Error = Infallible;
default fn try_clone(&self) -> Result<Self, Self::Error> {
Ok(self.clone())
}
default fn try_clone_from(&mut self, source: &Self) -> Result<(), Self::Error> {
self.clone_from(source);
Ok(())
}
}
mod core;
#[cfg(feature = "alloc")]
mod alloc;
#[cfg(feature = "std")]
mod std;
#[cfg(all(feature = "std", windows))]
mod windows;
#[cfg(all(feature = "std", unix))]
mod unix;