pub trait PClone<A: MemPool>: Sized {
    fn pclone(&self, journal: &Journal<A>) -> Self;

    fn pclone_from(&mut self, source: &Self, journal: &Journal<A>) { ... }
}
Expand description

A common trait for the ability to explicitly duplicate an object.

Differs from Copy in that Copy is implicit and extremely inexpensive, while PClone is always explicit and may or may not be expensive. Its difference with Clone is that it a &Journal to be used for logging in Prc and Parc. In order to enforce these characteristics, Rust does not allow you to reimplement Copy, but you may reimplement Clone and PClone and run arbitrary code.

Since PClone 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 PClone. The derived implementation of PClone calls pclone on each field. It uses default::Allocator by default. It is possible to change the pool type(s) by using pools() attribute.

For a generic struct, #[derive] implements PClone conditionally by adding bound Clone on generic parameters.

// `derive` implements PClone<Allocator> for Reading<T> when T is 
// PClone<Allocator>
#[derive(PClone)]
struct Reading<T> {
    frequency: T,
}
// `derive` implements PClone<P> and PClone<Q> for Reading<T> when T is 
// PClone<P> and PClone<Q> specified by `pools`.
#[derive(PClone)]
#[pools(P,Q)]
struct Reading<T> {
    frequency: T,
}

How can I implement PClone?

Types that are Copy should have a trivial implementation of PClone. More formally: if T: Copy, x: T, and y: &T, then let x = y.pclone(); 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. Note that, the implementation should be done for a specific (or generic) pool type.

Required Methods

Provided Methods

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

Implementors