W3cubDocs

/Rust

Trait TrivialClone

pub unsafe trait TrivialClone: Clone { }
🔬This is a nightly-only experimental API. (trivial_clone)

Indicates that the Clone implementation is identical to copying the value.

This is used for some optimizations in the standard library, which specializes on this trait to select faster implementations of functions such as clone_from_slice. It is automatically implemented when using #[derive(Clone, Copy)].

Note that this trait does not imply that the type is Copy, because e.g. core::ops::Range<i32> could soundly implement this trait.

Safety

Clone::clone must be equivalent to copying the value, otherwise calling functions such as slice::clone_from_slice can have undefined behaviour.

Dyn Compatibility

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors

© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/clone/trait.TrivialClone.html