Trait core::clone::Clone [] [src]

pub trait Clone: Sized {
    fn clone(&self) -> Self;

    fn clone_from(&mut self, source: &Self) { ... }
}

A common trait for cloning an object.

Required Methods

fn clone(&self) -> Self

Returns a copy of the value.

Examples

fn main() { let hello = "Hello"; // &str implements Clone assert_eq!("Hello", hello.clone()); }
let hello = "Hello"; // &str implements Clone

assert_eq!("Hello", hello.clone());

Provided Methods

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source`source`.

a.clone_from(&b)`a.clone_from(&b)is equivalent to` is equivalent to a = b.clone()`a = b.clone()in functionality, but can be overridden to reuse the resources of` in functionality, but can be overridden to reuse the resources of a`a` to avoid unnecessary allocations.

Implementors