Skip to main content

TryClone

Trait TryClone 

Source
pub trait TryClone: Sized {
    type Error;

    // Required method
    fn try_clone(&self) -> Result<Self, Self::Error>;

    // Provided method
    fn try_clone_from(&mut self, source: &Self) -> Result<(), Self::Error> { ... }
}
Expand description

A fallible variant of Clone.

this trait is intended for types where cloning can fail, for example due to allocation failures, resource limits, or external constraints.

Unlike Clone, the cloning operation returns a Result with an associated error type.

Required Associated Types§

Source

type Error

The error type returned when cloning fails.

Required Methods§

Source

fn try_clone(&self) -> Result<Self, Self::Error>

Tries to create a duplicate of the value.

§Errors

Returns Error if cloning fails.

Provided Methods§

Source

fn try_clone_from(&mut self, source: &Self) -> Result<(), Self::Error>

Performs copy-assignment from source. a.clone_from(&b) is equivalent to a = b.clone() in functionality, but can be overridden to reuse the resources of a to avoid unnecessary allocations.

§Errors

Returns Error if cloning fails.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl TryClone for File

Available on crate feature std only.
Source§

type Error = Error

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Source§

impl TryClone for OwnedFd

Available on Unix and crate feature std and neither Hermit nor Motor OS nor Trusty nor WebAssembly only.
Source§

type Error = Error

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Source§

impl TryClone for PipeReader

Available on crate feature std only.
Source§

type Error = Error

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Source§

impl TryClone for PipeWriter

Available on crate feature std only.
Source§

type Error = Error

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Source§

impl TryClone for TcpListener

Available on crate feature std only.
Source§

type Error = Error

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Source§

impl TryClone for TcpStream

Available on crate feature std only.
Source§

type Error = Error

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Source§

impl TryClone for UdpSocket

Available on crate feature std only.
Source§

type Error = Error

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Source§

impl TryClone for UnixDatagram

Available on Unix and crate feature std only.
Source§

type Error = Error

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Source§

impl TryClone for UnixListener

Available on Unix and crate feature std only.
Source§

type Error = Error

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Source§

impl TryClone for UnixStream

Available on Unix and crate feature std only.
Source§

type Error = Error

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Source§

impl<T: Clone + Ord, A: Allocator + Clone> TryClone for BinaryHeap<T, A>

Available on crate features alloc and nightly only.
Source§

impl<T: Clone, A: Allocator + Clone> TryClone for Arc<T, A>

Available on crate features alloc and nightly only.
Source§

type Error = AllocError

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Source§

impl<T: Clone, A: Allocator + Clone> TryClone for Rc<T, A>

Available on crate features alloc and nightly only.
Source§

type Error = AllocError

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Source§

impl<T: Clone, A: Allocator + Clone> TryClone for Vec<T, A>

Available on crate features alloc and nightly only.
Source§

impl<T: Clone, A: Allocator + Clone> TryClone for VecDeque<T, A>

Available on crate features alloc and nightly only.

Implementors§

Source§

impl<T: Clone + ForwardTryCloneToClone> TryClone for T

Available on crate feature blanket-impl only.