pub struct WriteEvent { /* private fields */ }Expand description
Context provided to write callbacks describing what changed in the database.
For local writes (transaction commits), this contains a single entry. For remote writes (sync), this may contain a batch of entries that were received and stored together.
§Catching up on missed writes
The previous_tips field contains the DAG tips of the database before the
write(s) that triggered this callback. Consumers can use this to determine
exactly what changed by walking the DAG from the current tips back to these
previous tips. This is analogous to git log previous_tip..HEAD.
This design means callbacks never need to “miss” writes — even if multiple entries are batched (as in sync), the consumer can reconstruct the full set of changes from the tip diff.
§Example
// Check what stores were touched
for entry in event.entries() {
if entry.in_subtree("messages") {
// A write touched the "messages" store
}
}
// Use previous_tips to find what's new
let prev = event.previous_tips();
// Walk DAG from current tips back to prev to find all new entriesImplementations§
Source§impl WriteEvent
impl WriteEvent
Sourcepub fn entries(&self) -> &[Entry]
pub fn entries(&self) -> &[Entry]
Get the entries written in this event.
For local writes (transaction commits), this always contains exactly one entry. For remote writes (sync), this contains the full batch of entries received together.
Sourcepub fn previous_tips(&self) -> &[ID]
pub fn previous_tips(&self) -> &[ID]
Get the DAG tips of the database before this write.
Use these to determine what changed: walk from the database’s current tips back to these previous tips to find all new entries.
Sourcepub fn source(&self) -> WriteSource
pub fn source(&self) -> WriteSource
The source of this write (local commit or remote sync).
Trait Implementations§
Source§impl Clone for WriteEvent
impl Clone for WriteEvent
Source§fn clone(&self) -> WriteEvent
fn clone(&self) -> WriteEvent
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for WriteEvent
impl RefUnwindSafe for WriteEvent
impl Send for WriteEvent
impl Sync for WriteEvent
impl Unpin for WriteEvent
impl UnsafeUnpin for WriteEvent
impl UnwindSafe for WriteEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more