pub trait Apply<T, A>: Sized {
// Required method
fn apply_first(&mut self, first: &mut T, second: &T, auxiliary: &mut A);
// Provided method
fn apply_second(self, first: &T, second: &mut T, auxiliary: &mut A) { ... }
}Expand description
Types that can incorporate operations of type O.
This trait allows left-right to keep the two copies of the underlying data structure (see the
crate-level documentation) the same over time. Each write operation to the data
structure is logged as an operation of type O in an operational log (oplog), and is applied
once to each copy of the data.
Implementations should ensure that the application of each operation is deterministic. That is, if
two instances of the type T are initially equal, and the same operation is applied to both of them,
they should remain equal afterwards. If this is not the case, the two copies will drift apart
over time, and hold different values.
The trait provides separate methods for the first and second application of each operation. For many
implementations, these will be the same (which is why apply_second defaults to calling
apply_first), but not all. In particular, some implementations may need to modify the operation to
ensure deterministic results when it is applied to the second copy.
Required Methods§
Sourcefn apply_first(&mut self, first: &mut T, second: &T, auxiliary: &mut A)
fn apply_first(&mut self, first: &mut T, second: &T, auxiliary: &mut A)
Apply O to the first of the two copies.
other is a reference to the other copy of the data, which has seen all operations up
until the previous call to WriteHandle::publish. That is, other is one “publish
cycle” behind.
Provided Methods§
Sourcefn apply_second(self, first: &T, second: &mut T, auxiliary: &mut A)
fn apply_second(self, first: &T, second: &mut T, auxiliary: &mut A)
Apply O to the second of the two copies.
other is a reference to the other copy of the data, which has seen all operations up to
the call to WriteHandle::publish that initially exposed this O. That is, other is
one “publish cycle” ahead.
Note that this method should modify the underlying data in exactly the same way as
O modified other, otherwise the two copies will drift apart. Be particularly mindful of
non-deterministic implementations of traits that are often assumed to be deterministic
(like Eq and Hash), and of “hidden states” that subtly affect results like the
RandomState of a HashMap which can change iteration order.
Defaults to calling apply_first.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.