pub trait Mutable:
Contiguous
+ Send
+ Sync {
// Required methods
fn append(
&mut self,
item: &Self::Item,
) -> impl Future<Output = Result<u64, Error>> + Send;
fn prune(
&mut self,
min_position: u64,
) -> impl Future<Output = Result<bool, Error>> + Send;
fn rewind(
&mut self,
size: u64,
) -> impl Future<Output = Result<(), Error>> + Send;
// Provided methods
fn append_many<'a>(
&'a mut self,
items: Many<'a, Self::Item>,
) -> impl Future<Output = Result<u64, Error>> + Send + 'a
where Self::Item: Sync { ... }
fn rewind_to<'a, P>(
&'a mut self,
predicate: P,
) -> impl Future<Output = Result<u64, Error>> + Send + 'a
where P: FnMut(&Self::Item) -> bool + Send + 'a { ... }
}Expand description
A Contiguous journal that supports appending, rewinding, and pruning.
Required Methods§
Sourcefn append(
&mut self,
item: &Self::Item,
) -> impl Future<Output = Result<u64, Error>> + Send
fn append( &mut self, item: &Self::Item, ) -> impl Future<Output = Result<u64, Error>> + Send
Append a new item to the journal, returning its position.
Positions are consecutively increasing starting from 0. The position of each item is stable across pruning (i.e., if item X has position 5, it will always have position 5 even if earlier items are pruned).
§Errors
Returns an error if the underlying storage operation fails or if the item cannot be encoded.
Sourcefn prune(
&mut self,
min_position: u64,
) -> impl Future<Output = Result<bool, Error>> + Send
fn prune( &mut self, min_position: u64, ) -> impl Future<Output = Result<bool, Error>> + Send
Prune items at positions strictly less than min_position.
Returns true if any data was pruned, false otherwise.
§Behavior
- If
min_position > bounds.end, the prune is capped tobounds.end(no error is returned) - Some items with positions less than
min_positionmay be retained due to section/blob alignment - This operation is not atomic, but implementations guarantee the journal is left in a recoverable state if a crash occurs during pruning
§Errors
Returns an error if the underlying storage operation fails.
Sourcefn rewind(
&mut self,
size: u64,
) -> impl Future<Output = Result<(), Error>> + Send
fn rewind( &mut self, size: u64, ) -> impl Future<Output = Result<(), Error>> + Send
Rewind the journal to the given size, discarding items from the end.
After rewinding to size N, the journal will contain exactly N items (positions 0 to N-1), and the next append will receive position N.
§Behavior
- If
size > bounds.end, returns Error::InvalidRewind - If
size == bounds.end, this is a no-op - If
size < bounds.start, returns Error::ItemPruned (can’t rewind to pruned data) - This operation is not atomic, but implementations guarantee the journal is left in a recoverable state if a crash occurs during rewinding
§Warnings
- This operation is not guaranteed to survive restarts until
commitorsyncis called.
§Errors
Returns Error::InvalidRewind if size is invalid (too large or points to pruned data). Returns an error if the underlying storage operation fails.
Provided Methods§
Sourcefn append_many<'a>(
&'a mut self,
items: Many<'a, Self::Item>,
) -> impl Future<Output = Result<u64, Error>> + Send + 'a
fn append_many<'a>( &'a mut self, items: Many<'a, Self::Item>, ) -> impl Future<Output = Result<u64, Error>> + Send + 'a
Append items to the journal, returning the position of the last item appended.
The default implementation calls Self::append in a loop. Concrete implementations may override this to acquire the write lock once for all items.
Returns Error::EmptyAppend if items is empty.
Sourcefn rewind_to<'a, P>(
&'a mut self,
predicate: P,
) -> impl Future<Output = Result<u64, Error>> + Send + 'a
fn rewind_to<'a, P>( &'a mut self, predicate: P, ) -> impl Future<Output = Result<u64, Error>> + Send + 'a
Rewinds the journal to the last item matching predicate. If no item matches, the journal
is rewound to the pruning boundary, discarding all unpruned items.
§Warnings
- This operation is not guaranteed to survive restarts until
commitorsyncis called.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".