Trait std::clone::Clone [] [src]

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

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

A common trait for cloning an object.

This trait can be used with #[derive].

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.

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.

Implementors