pub trait ListMutTarget<T: Copy> {
// Required methods
fn len(&self) -> usize;
fn get_mut(&mut self, index: usize) -> Option<&mut T>;
fn push(&mut self, value: T);
// Provided method
fn is_empty(&self) -> bool { ... }
}Expand description
A mutable target for list-like collections of copyable values.
ListMutTarget provides the minimal interface required by the generic
delta-application routines in this crate. It allows those routines to
update consensus-state collections without requiring the collection to be
backed by a contiguous Vec.
Implementations may use any underlying storage strategy, including contiguous buffers, persistent trees, or other client-specific data structures.
§Type parameter
T is the element type stored by the collection. It must implement
Copy because delta application reads values from the encoded delta and
writes them directly into the target collection.
§Required operations
An implementation must provide:
lento report the current number of elements.get_mutto obtain mutable access to an existing element by index.pushto append a newly decoded element.
§Example
The crate provides an implementation for Vec<u64> and Vec<u8>.
use eth_state_diff::ListMutTarget;
let mut values = vec![100u64, 200, 300];
let target: &mut dyn ListMutTarget<u64> = &mut values;
*target.get_mut(1).unwrap() = 250;
target.push(400);
assert_eq!(values, [100, 250, 300, 400]);§Implementing for client-specific collections
Consensus clients with non-contiguous or tree-backed state can implement this trait to allow the generic delta algorithms to operate directly on their native collections, without first materializing the collection as a flat buffer.
Implementations should return None from get_mut when
the requested index is outside the current collection bounds.
Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".