Movatterモバイル変換


[0]ホーム

URL:


Module clone

core

Moduleclone 

1.6.0 ·Source
Expand description

TheClone trait for types that cannot be ‘implicitly copied’.

In Rust, some simple types are “implicitly copyable” and when youassign them or pass them as arguments, the receiver will get a copy,leaving the original value in place. These types do not requireallocation to copy and do not have finalizers (i.e., they do notcontain owned boxes or implementDrop), so the compiler considersthem cheap and safe to copy. For other types copies must be madeexplicitly, by convention implementing theClone trait and callingtheclone method.

Basic usage example:

lets = String::new();// String type implements Cloneletcopy = s.clone();// so we can clone it

To easily implement the Clone trait, you can also use#[derive(Clone)]. Example:

#[derive(Clone)]// we add the Clone trait to Morpheus structstructMorpheus {   blue_pill: f32,   red_pill: i64,}fnmain() {letf = Morpheus { blue_pill:0.0, red_pill:0};letcopy = f.clone();// and now we can clone it!}

Traits§

Clone
A common trait that allows explicit creation of a duplicate value.
CloneToUninitExperimental
A generalization ofClone todynamically-sized types stored in arbitrary containers.
TrivialCloneExperimental
Indicates that theClone implementation is identical to copying the value.
UseClonedExperimental
Trait for objects whoseClone impl is lightweight (e.g. reference-counted)

Derive Macros§

Clone
Derive macro generating an impl of the traitClone.

[8]ページ先頭

©2009-2025 Movatter.jp