pub struct CloneReplace<T> { /* private fields */ }
Expand description

A shareable store for data which provides owned references.

A CloneReplace stores a reference version of an enclosed data structure. An owned snapshot of the current reference version can be retrieved by calling access on CloneReplace, which will preserve the reference version at that moment until it is dropped. A mutatable snapshot of the current reference version can be retrieved by calling mutate on CloneReplace, and when this goes out of scope, the reference version at that moment will be replaced by the mutated one.

Implementations

Create a new CloneReplace.

Example:

use clone_replace::CloneReplace;

struct Foo {
   a: i32
}

let cr = CloneReplace::new(Foo { a: 0 });

Retrieve a snapshot of the current reference version of the data.

The return value is owned, and the snapshot taken will remain unchanging until it goes out of scope. The existence of the snapshot will not prevent the reference version from evolving, so holding snapshots must be carefully considered, as it can lead to memory pressure.

Example:

use clone_replace::CloneReplace;

let c = CloneReplace::new(1);
let v = c.access();
assert_eq!(*v, 1);

Create a mutable replacement for the reference data.

A copy of the current reference version of the data is created. The MutateGuard provides mutable references to that data. When the guard goes out of scope the reference version will be overwritten with the updated version.

Multiple guards can exist simultaneously, and there is no attempt to prevent loss of data from stale updates. An internally consistent version of the data, as produced by a single mutate call, will always exist, but not every mutate call will end up being reflected in a reference version of the data. This is a significantly weaker consistency guarantee than a Mutex provides, for example.

Example:

use clone_replace::CloneReplace;

let c = CloneReplace::new(1);
let mut v = c.mutate();
*v = 2;
drop(v);
assert_eq!(*c.access(), 2);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.