Skip to main content

FieldCursor

Trait FieldCursor 

Source
pub trait FieldCursor:
    Default
    + Clone
    + Debug {
    type Changes: ChangeReport;

    // Required methods
    fn diff<D: ReadDoc>(&self, doc: &D, obj: &ObjId) -> Result<Self::Changes>;
    fn refresh<D: ReadDoc>(&mut self, doc: &D, obj: &ObjId) -> Result<()>;

    // Provided method
    fn has_changes<D: ReadDoc>(&self, doc: &D, obj: &ObjId) -> Result<bool> { ... }
}
Expand description

Trait for cursor types that cache ObjIds for O(1) change detection.

Cursors are generated for structs and cache the ObjId of each field. When checking for changes, the cursor compares its cached ObjIds against the document’s current ObjIds, avoiding expensive value deserialization.

Required Associated Types§

Source

type Changes: ChangeReport

The associated change report type.

Required Methods§

Source

fn diff<D: ReadDoc>(&self, doc: &D, obj: &ObjId) -> Result<Self::Changes>

Compares cached ObjIds against the document to detect changes.

Returns a hierarchical change report indicating which fields changed.

Source

fn refresh<D: ReadDoc>(&mut self, doc: &D, obj: &ObjId) -> Result<()>

Refreshes the cached ObjIds from the document.

Should be called after update to keep the cursor in sync.

Provided Methods§

Source

fn has_changes<D: ReadDoc>(&self, doc: &D, obj: &ObjId) -> Result<bool>

Checks if any cached ObjIds differ from the document.

This is a fast O(field count) check.

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.

Implementors§