Trait frame_support::dispatch::Clone 1.0.0[−][src]
pub trait Clone {
fn clone(&self) -> Self;
fn clone_from(&mut self, source: &Self) { ... }
}Expand description
A common trait for the ability to explicitly duplicate an object.
Differs from Copy in that Copy is implicit and an inexpensive bit-wise copy, while
Clone is always explicit and may or may not be expensive. In order to enforce
these characteristics, Rust does not allow you to reimplement Copy, but you
may reimplement Clone and run arbitrary code.
Since Clone is more general than Copy, you can automatically make anything
Copy be Clone as well.
Derivable
This trait can be used with #[derive] if all fields are Clone. The derived
implementation of Clone calls clone on each field.
For a generic struct, #[derive] implements Clone conditionally by adding bound Clone on
generic parameters.
// `derive` implements Clone for Reading<T> when T is Clone. #[derive(Clone)] struct Reading<T> { frequency: T, }
How can I implement Clone?
Types that are Copy should have a trivial implementation of Clone. More formally:
if T: Copy, x: T, and y: &T, then let x = y.clone(); is equivalent to let x = *y;.
Manual implementations should be careful to uphold this invariant; however, unsafe code
must not rely on it to ensure memory safety.
An example is a generic struct holding a function pointer. In this case, the
implementation of Clone cannot be derived, but can be implemented as:
struct Generate<T>(fn() -> T); impl<T> Copy for Generate<T> {} impl<T> Clone for Generate<T> { fn clone(&self) -> Self { *self } }
Additional implementors
In addition to the implementors listed below,
the following types also implement Clone:
- Function item types (i.e., the distinct types defined for each function)
- Function pointer types (e.g.,
fn() -> i32) - Array types, for all sizes, if the item type also implements
Clone(e.g.,[i32; 123456]) - Tuple types, if each component also implements
Clone(e.g.,(),(i32, bool)) - Closure types, if they capture no value from the environment
or if all such captured values implement
Clonethemselves. Note that variables captured by shared reference always implementClone(even if the referent doesn’t), while variables captured by mutable reference never implementClone.
Required methods
Provided methods
fn clone_from(&mut self, source: &Self)
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.
Implementations on Foreign Types
Clone a sender to send to other threads.
Note, be aware of the lifetime of the sender because all senders
(including the original) need to be dropped in order for
Receiver::recv to stop blocking.
impl<I, U, F> Clone for FlatMap<I, U, F> where
I: Clone,
F: Clone,
U: Clone + IntoIterator,
<U as IntoIterator>::IntoIter: Clone,
impl<I, U, F> Clone for FlatMap<I, U, F> where
I: Clone,
F: Clone,
U: Clone + IntoIterator,
<U as IntoIterator>::IntoIter: Clone, Shared references can be cloned, but mutable references cannot!
Shared references can be cloned, but mutable references cannot!
Returns a new box with a clone() of this box’s contents.
Examples
let x = Box::new(5); let y = x.clone(); // The value is the same assert_eq!(x, y); // But they are unique objects assert_ne!(&*x as *const i32, &*y as *const i32);
Copies source’s contents into self without creating a new allocation.
Examples
let x = Box::new(5); let mut y = Box::new(10); let yp: *const i32 = &*y; y.clone_from(&x); // The value is the same assert_eq!(x, y); // And no allocation occurred assert_eq!(yp, &*y);
impl<'c, 't> Clone for SubCaptureMatches<'c, 't> where
't: 'c,
impl<'c, 't> Clone for SubCaptureMatches<'c, 't> where
't: 'c, pub fn clone(&self) -> SubCaptureMatches<'c, 't>impl<'c, 't> Clone for SubCaptureMatches<'c, 't> where
't: 'c,
impl<'c, 't> Clone for SubCaptureMatches<'c, 't> where
't: 'c, pub fn clone(&self) -> SubCaptureMatches<'c, 't>pub fn clone(&self) -> IntoIter<A>pub fn clone(&self) -> SmallVec<A>impl Clone for __c_anonymous_sockaddr_can_j1939
impl Clone for __c_anonymous_sockaddr_can_j1939pub fn clone(&self) -> __c_anonymous_sockaddr_can_j1939impl Clone for __c_anonymous_sockaddr_can_can_addr
impl Clone for __c_anonymous_sockaddr_can_can_addrpub fn clone(&self) -> __c_anonymous_sockaddr_can_can_addrpub fn clone(&self) -> Matcher<'a, S, A>pub fn clone(&self) -> Pattern<S, A>pub fn clone(&self) -> ByteClass<T, S>pub fn clone(&self) -> PremultipliedByteClass<T, S>pub fn clone(&self) -> Standard<T, S>pub fn clone(&self) -> Premultiplied<T, S>pub fn clone(&self) -> ByteClass<T, S>pub fn clone(&self) -> SparseDFA<T, S>pub fn clone(&self) -> Standard<T, S>pub fn clone(&self) -> DenseDFA<T, S>Cloning an ANSIGenericString will clone its underlying string.
Examples
use ansi_term::ANSIString; let plain_string = ANSIString::from("a plain string"); let clone_string = plain_string.clone(); assert_eq!(clone_string, plain_string);
pub fn clone(&self) -> ANSIGenericString<'a, S>impl<Number, Hash> Clone for ChangesTrieConfigurationRange<Number, Hash> where
Hash: Clone,
Number: Clone,
impl<Number, Hash> Clone for ChangesTrieConfigurationRange<Number, Hash> where
Hash: Clone,
Number: Clone, pub fn clone(&self) -> CountedList<T>impl<I, T> Clone for CountedListWriter<I, T> where
I: Serialize<Error = Error> + Clone,
T: Clone + IntoIterator<Item = I>,
impl<I, T> Clone for CountedListWriter<I, T> where
I: Serialize<Error = Error> + Clone,
T: Clone + IntoIterator<Item = I>, pub fn clone(&self) -> CountedListWriter<I, T>impl<R, Rsdr> Clone for ReseedingRng<R, Rsdr> where
R: BlockRngCore + SeedableRng + Clone,
Rsdr: RngCore + Clone,
impl<R, Rsdr> Clone for ReseedingRng<R, Rsdr> where
R: BlockRngCore + SeedableRng + Clone,
Rsdr: RngCore + Clone, impl<X> Clone for WeightedIndex<X> where
X: Clone + SampleUniform + PartialOrd<X>,
<X as SampleUniform>::Sampler: Clone,
impl<X> Clone for WeightedIndex<X> where
X: Clone + SampleUniform + PartialOrd<X>,
<X as SampleUniform>::Sampler: Clone, impl<X> Clone for Uniform<X> where
X: Clone + SampleUniform,
<X as SampleUniform>::Sampler: Clone,
impl<X> Clone for Uniform<X> where
X: Clone + SampleUniform,
<X as SampleUniform>::Sampler: Clone, impl<R> Clone for BlockRng64<R> where
R: Clone + BlockRngCore + ?Sized,
<R as BlockRngCore>::Results: Clone,
impl<R> Clone for BlockRng64<R> where
R: Clone + BlockRngCore + ?Sized,
<R as BlockRngCore>::Results: Clone, impl<R> Clone for BlockRng<R> where
R: Clone + BlockRngCore + ?Sized,
<R as BlockRngCore>::Results: Clone,
impl<R> Clone for BlockRng<R> where
R: Clone + BlockRngCore + ?Sized,
<R as BlockRngCore>::Results: Clone, pub fn clone(&self) -> SseMachine<S3, S4, NI>pub fn clone(&self) -> BlockBuffer<BlockSize>pub fn clone(&self) -> GenericArray<T, N>pub fn clone(&self) -> GenericArrayIter<T, N>impl<R, Rsdr> Clone for ReseedingRng<R, Rsdr> where
R: BlockRngCore + SeedableRng + Clone,
Rsdr: RngCore + Clone,
impl<R, Rsdr> Clone for ReseedingRng<R, Rsdr> where
R: BlockRngCore + SeedableRng + Clone,
Rsdr: RngCore + Clone, impl<X> Clone for Uniform<X> where
X: Clone + SampleUniform,
<X as SampleUniform>::Sampler: Clone,
impl<X> Clone for Uniform<X> where
X: Clone + SampleUniform,
<X as SampleUniform>::Sampler: Clone, impl<X> Clone for WeightedIndex<X> where
X: Clone + SampleUniform + PartialOrd<X>,
<X as SampleUniform>::Sampler: Clone,
impl<X> Clone for WeightedIndex<X> where
X: Clone + SampleUniform + PartialOrd<X>,
<X as SampleUniform>::Sampler: Clone, impl<R> Clone for BlockRng64<R> where
R: Clone + BlockRngCore + ?Sized,
<R as BlockRngCore>::Results: Clone,
impl<R> Clone for BlockRng64<R> where
R: Clone + BlockRngCore + ?Sized,
<R as BlockRngCore>::Results: Clone, impl<R> Clone for BlockRng<R> where
R: Clone + BlockRngCore + ?Sized,
<R as BlockRngCore>::Results: Clone,
impl<R> Clone for BlockRng<R> where
R: Clone + BlockRngCore + ?Sized,
<R as BlockRngCore>::Results: Clone, pub fn clone(&self) -> TinyVec<A>pub fn clone(&self) -> Hmac<D>pub fn clone(&self) -> Output<M>pub fn clone(&self) -> SharedSecret<D>pub fn clone(&self) -> GenericArrayIter<T, N>pub fn clone(&self) -> GenericArray<T, N>pub fn clone(&self) -> Hmac<D>pub fn clone(&self) -> MacResult<N>pub fn clone(&self) -> BlockBuffer<BlockSize>pub fn clone(&self) -> Malleable<T>pub fn clone(&self) -> Intersection<'_, T, S, A>pub fn clone(&self) -> HashMap<K, V, S, A>pub fn clone_from(&mut self, source: &HashMap<K, V, S, A>)pub fn clone(&self) -> Union<'_, T, S, A>pub fn clone(&self) -> SymmetricDifference<'_, T, S, A>pub fn clone(&self) -> Difference<'_, T, S, A>pub fn clone(&self) -> HashSet<T, S, A>pub fn clone_from(&mut self, source: &HashSet<T, S, A>)pub fn clone(&self) -> WeakShared<Fut>pub fn clone(&self) -> Shared<Fut>pub fn clone(&self) -> SinkMapErr<Si, F>pub fn clone(&self) -> With<Si, Item, U, Fut, F>pub fn clone(&self) -> TrieError<T, E>pub fn clone(&self) -> LegacyPrefixedKey<H>pub fn clone(&self) -> MemoryDB<H, KF, T, M>pub fn clone(&self) -> EntriesCursor<'abbrev, 'unit, R>pub fn clone(&self) -> CompleteLineProgram<R, Offset>pub fn clone(&self) -> UnitHeader<R, Offset>pub fn clone(&self) -> LocationListsOffset<T>pub fn clone(&self) -> Operation<R, Offset>pub fn clone(&self) -> Piece<R, Offset>pub fn clone(&self) -> EntriesTree<'abbrev, 'unit, R>pub fn clone(&self) -> FileEntry<R, Offset>pub fn clone(&self) -> DebugLocListsIndex<T>pub fn clone(&self) -> LineInstruction<R, Offset>pub fn clone(&self) -> DebugStrOffsetsIndex<T>pub fn clone(&self) -> CfiEntriesIter<'bases, Section, R>pub fn clone(&self) -> EndianSlice<'input, Endian>pub fn clone(&self) -> LineProgramHeader<R, Offset>pub fn clone(&self) -> ParsedEhFrameHdr<R>pub fn clone(&self) -> UnitType<Offset>pub fn clone(&self) -> PubNamesEntry<R>pub fn clone(&self) -> LocationListEntry<R>pub fn clone(&self) -> CallFrameInstructionIter<'a, R>pub fn clone(&self) -> DebugRngListsIndex<T>pub fn clone(&self) -> PubTypesEntryIter<R>pub fn clone(&self) -> UninitializedUnwindContext<R>pub fn clone(&self) -> DebugLineStrOffset<T>pub fn clone(&self) -> DebugMacinfoOffset<T>pub fn clone(&self) -> FrameDescriptionEntry<R, Offset>pub fn clone(&self) -> LineRows<R, Program, Offset>pub fn clone(&self) -> AttrsIter<'abbrev, 'entry, 'unit, R>pub fn clone(&self) -> IncompleteLineProgram<R, Offset>pub fn clone(&self) -> Location<R, Offset>pub fn clone(&self) -> ArangeEntryIter<R>pub fn clone(&self) -> DebugStrOffsetsBase<T>pub fn clone(&self) -> LineInstructions<R>pub fn clone(&self) -> DebuggingInformationEntry<'abbrev, 'unit, R, Offset>pub fn clone(&self) -> PartialFrameDescriptionEntry<'bases, Section, R>pub fn clone(&self) -> RawLocListEntry<R>pub fn clone(&self) -> CallFrameInstruction<R>pub fn clone(&self) -> DebugInfoUnitHeadersIter<R>pub fn clone(&self) -> PubTypesEntry<R>pub fn clone(&self) -> PubNamesEntryIter<R>pub fn clone(&self) -> EntriesRaw<'abbrev, 'unit, R>pub fn clone(&self) -> AttributeValue<R, Offset>pub fn clone(&self) -> CommonInformationEntry<R, Offset>pub fn clone(&self) -> DebugTypesUnitHeadersIter<R>pub fn clone(&self) -> RegisterRuleIter<'iter, R>pub fn clone(&self) -> UnwindTableRow<R>pub fn clone(&self) -> CieOrFde<'bases, Section, R>pub fn clone(&self) -> EhHdrTable<'a, R>pub fn clone(&self) -> FvmfileCommand<E>pub fn clone(&self) -> ElfSymbolTable<'data, 'file, Elf>pub fn clone(&self) -> ProgramHeader32<E>pub fn clone(&self) -> EncryptionInfoCommand64<E>impl Clone for ImageAlpha64RuntimeFunctionEntry
impl Clone for ImageAlpha64RuntimeFunctionEntrypub fn clone(&self) -> ImageAlpha64RuntimeFunctionEntrypub fn clone(&self) -> MachOSymbolTable<'data, 'file, Mach>impl Clone for ImagePrologueDynamicRelocationHeader
impl Clone for ImagePrologueDynamicRelocationHeaderpub fn clone(&self) -> ImagePrologueDynamicRelocationHeaderpub fn clone(&self) -> SegmentCommand64<E>impl<'data, 'file> Clone for CoffSymbol<'data, 'file> where
'data: 'file,
impl<'data, 'file> Clone for CoffSymbol<'data, 'file> where
'data: 'file, pub fn clone(&self) -> CoffSymbol<'data, 'file>pub fn clone(&self) -> ElfSymbol<'data, 'file, Elf>pub fn clone(&self) -> CompressionHeader32<E>pub fn clone(&self) -> DylibReference<E>pub fn clone(&self) -> CompressionHeader64<E>pub fn clone(&self) -> BuildVersionCommand<E>pub fn clone(&self) -> MachOSymbol<'data, 'file, Mach>pub fn clone(&self) -> BuildToolVersion<E>pub fn clone(&self) -> SymbolTable<'data, Elf>pub fn clone(&self) -> LinkeditDataCommand<E>pub fn clone(&self) -> DylinkerCommand<E>pub fn clone(&self) -> SubFrameworkCommand<E>pub fn clone(&self) -> LinkerOptionCommand<E>pub fn clone(&self) -> EncryptionInfoCommand<E>pub fn clone(&self) -> DyldInfoCommand<E>pub fn clone(&self) -> DysymtabCommand<E>pub fn clone(&self) -> SegmentCommand32<E>pub fn clone(&self) -> SubClientCommand<E>pub fn clone(&self) -> SymbolFlags<Section>pub fn clone(&self) -> SourceVersionCommand<E>pub fn clone(&self) -> ProgramHeader64<E>pub fn clone(&self) -> SectionHeader32<E>pub fn clone(&self) -> DylibTableOfContents<E>pub fn clone(&self) -> DataInCodeEntry<E>pub fn clone(&self) -> EntryPointCommand<E>pub fn clone(&self) -> SymbolTable<'data, Mach>pub fn clone(&self) -> RoutinesCommand_64<E>pub fn clone(&self) -> TwolevelHintsCommand<E>pub fn clone(&self) -> PrebindCksumCommand<E>impl<'data, 'file> Clone for CoffSymbolTable<'data, 'file> where
'data: 'file,
impl<'data, 'file> Clone for CoffSymbolTable<'data, 'file> where
'data: 'file, pub fn clone(&self) -> CoffSymbolTable<'data, 'file>impl Clone for ImageEpilogueDynamicRelocationHeader
impl Clone for ImageEpilogueDynamicRelocationHeaderpub fn clone(&self) -> ImageEpilogueDynamicRelocationHeaderpub fn clone(&self) -> SubLibraryCommand<E>pub fn clone(&self) -> SubUmbrellaCommand<E>pub fn clone(&self) -> SectionHeader64<E>pub fn clone(&self) -> PreboundDylibCommand<E>pub fn clone(&self) -> SectionTable<'data, Elf>pub fn clone(&self) -> VersionMinCommand<E>pub fn clone(&self) -> RoutinesCommand<E>impl<Address, Call, Signature, Extra> Clone for UncheckedExtrinsic<Address, Call, Signature, Extra> where
Call: Clone,
Extra: Clone + SignedExtension,
Address: Clone,
Signature: Clone,
impl<Address, Call, Signature, Extra> Clone for UncheckedExtrinsic<Address, Call, Signature, Extra> where
Call: Clone,
Extra: Clone + SignedExtension,
Address: Clone,
Signature: Clone, impl<AccountId, AccountIndex> Clone for MultiAddress<AccountId, AccountIndex> where
AccountId: Clone,
AccountIndex: Clone,
impl<AccountId, AccountIndex> Clone for MultiAddress<AccountId, AccountIndex> where
AccountId: Clone,
AccountIndex: Clone, impl<Reporter, Offender> Clone for OffenceDetails<Reporter, Offender> where
Reporter: Clone,
Offender: Clone,
impl<Reporter, Offender> Clone for OffenceDetails<Reporter, Offender> where
Reporter: Clone,
Offender: Clone,