pub struct ChangeTracker { /* private fields */ }Expand description
Tracks changes to objects in the session.
Uses snapshot comparison to detect when objects have been modified.
Implementations§
Source§impl ChangeTracker
impl ChangeTracker
Sourcepub fn snapshot<T: Model + Serialize>(&mut self, key: ObjectKey, obj: &T)
pub fn snapshot<T: Model + Serialize>(&mut self, key: ObjectKey, obj: &T)
Take a snapshot of an object.
This stores the serialized state of the object for later comparison.
Sourcepub fn snapshot_raw(&mut self, key: ObjectKey, data: Vec<u8>)
pub fn snapshot_raw(&mut self, key: ObjectKey, data: Vec<u8>)
Take a snapshot from raw bytes.
Sourcepub fn is_dirty<T: Model + Serialize>(&self, key: &ObjectKey, obj: &T) -> bool
pub fn is_dirty<T: Model + Serialize>(&self, key: &ObjectKey, obj: &T) -> bool
Check if an object has changed since its snapshot.
Returns true if:
- The object has no snapshot (treated as dirty)
- The current state differs from the snapshot
Sourcepub fn is_dirty_raw(&self, key: &ObjectKey, current: &[u8]) -> bool
pub fn is_dirty_raw(&self, key: &ObjectKey, current: &[u8]) -> bool
Check if raw bytes match the snapshot.
Sourcepub fn changed_fields<T: Model + Serialize>(
&self,
key: &ObjectKey,
obj: &T,
) -> Vec<&'static str>
pub fn changed_fields<T: Model + Serialize>( &self, key: &ObjectKey, obj: &T, ) -> Vec<&'static str>
Get changed fields between snapshot and current state.
Returns a list of field names that have different values.
Sourcepub fn changed_fields_raw(
&self,
key: &ObjectKey,
current_bytes: &[u8],
field_names: &[&'static str],
) -> Vec<&'static str>
pub fn changed_fields_raw( &self, key: &ObjectKey, current_bytes: &[u8], field_names: &[&'static str], ) -> Vec<&'static str>
Get changed fields from raw JSON bytes.
Sourcepub fn attribute_changes<T: Model + Serialize>(
&self,
key: &ObjectKey,
obj: &T,
) -> Vec<AttributeChange>
pub fn attribute_changes<T: Model + Serialize>( &self, key: &ObjectKey, obj: &T, ) -> Vec<AttributeChange>
Get detailed attribute changes between snapshot and current state.
Returns AttributeChange structs with field name, old value, and new value.
Sourcepub fn has_snapshot(&self, key: &ObjectKey) -> bool
pub fn has_snapshot(&self, key: &ObjectKey) -> bool
Check if a snapshot exists for the given key.
Sourcepub fn get_snapshot(&self, key: &ObjectKey) -> Option<&ObjectSnapshot>
pub fn get_snapshot(&self, key: &ObjectKey) -> Option<&ObjectSnapshot>
Get the snapshot for a key.
Sourcepub fn clear(&mut self, key: &ObjectKey)
pub fn clear(&mut self, key: &ObjectKey)
Clear snapshot for a specific object.
Call this after commit or when discarding changes.
Sourcepub fn clear_all(&mut self)
pub fn clear_all(&mut self)
Clear all snapshots.
Call this after commit or rollback to reset tracking state.