pub trait ToOwned { typeOwned:Borrow<Self>; // Required method fnto_owned(&self) -> Self::Owned; // Provided method fnclone_into(&self, target: &mut Self::Owned) { ... }}
Expand description
A generalization ofClone
to borrowed data.
Some types make it possible to go from borrowed to owned, usually byimplementing theClone
trait. ButClone
works only for going from&T
toT
. TheToOwned
trait generalizesClone
to construct owned datafrom any borrow of a given type.
Required Associated Types§
Required Methods§
Provided Methods§
1.63.0 ·Sourcefnclone_into(&self, target: &mut Self::Owned)
fnclone_into(&self, target: &mut Self::Owned)
Uses borrowed data to replace owned data, usually by cloning.
This is borrow-generalized version ofClone::clone_from
.
§Examples
Basic usage:
Dyn Compatibility§
This trait isnotdyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.