Stdlibcore
clone
import std::core::clone; — in the prelude · source
Clone
type trait Clone {
clone(&this) -> This;
}
Clone produces an independent copy: a heap-owning type allocates fresh storage and copies the contents; a POD type copies bitwise. It stays distinct from Copy so generic code can ask for the weaker promise - a Clone bound says "I can duplicate this if I ask", a Copy bound says "duplicating this is free and implicit".
The containers implement it parametrically: Array<T> is Clone when T is, and its clone is a deep copy into a fresh buffer. Rc and Arc deliberately do not implement Clone - their clone is an inherent method - so a T: Clone bound on a pointee is never satisfied by a cheap handle copy.
Implementors
implement trait Clone for i8
implement trait Clone for i16
implement trait Clone for i32
implement trait Clone for i64
implement trait Clone for u8
implement trait Clone for u16
implement trait Clone for u32
implement trait Clone for u64
implement trait Clone for i128
implement trait Clone for u128
implement trait Clone for usize
implement trait Clone for isize
implement trait Clone for f32
implement trait Clone for f64
implement trait Clone for boolean
implement trait Clone for char
implement<T> trait Clone for struct Box<T, GlobalAlloc>
where T: Clone // std::alloc::box
implement<T> trait Clone for struct Array<T, GlobalAlloc>
where T: Clone // std::collections::array
implement<K, V> trait Clone for struct HashMap<K, V, GlobalAlloc>
where K: Hash + Eq + Clone, V: Clone // std::collections::hashmap
implement<T> trait Clone for struct HashSet<T, GlobalAlloc>
where T: Hash + Eq + Clone // std::collections::hashset
implement<A, B> trait Clone for struct Pair<A, B>
where A: Clone, B: Clone // std::collections::pair
implement trait Clone for struct String<GlobalAlloc> // std::collections::string
implement<T> trait Clone for enum Option<T>
where T: Clone // std::core::option
implement<T, E> trait Clone for enum Result<T, E>
where T: Clone, E: Clone // std::core::result
string, the raw C-string view, has no Clone - there is nothing sensible to copy it into.