Skip to main content

ChangeTracker

Struct ChangeTracker 

Source
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

Source

pub fn new() -> Self

Create a new empty change tracker.

Source

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.

Source

pub fn snapshot_raw(&mut self, key: ObjectKey, data: Vec<u8>)

Take a snapshot from raw bytes.

Source

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
Source

pub fn is_dirty_raw(&self, key: &ObjectKey, current: &[u8]) -> bool

Check if raw bytes match the snapshot.

Source

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.

Source

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.

Source

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.

Source

pub fn has_snapshot(&self, key: &ObjectKey) -> bool

Check if a snapshot exists for the given key.

Source

pub fn get_snapshot(&self, key: &ObjectKey) -> Option<&ObjectSnapshot>

Get the snapshot for a key.

Source

pub fn clear(&mut self, key: &ObjectKey)

Clear snapshot for a specific object.

Call this after commit or when discarding changes.

Source

pub fn clear_all(&mut self)

Clear all snapshots.

Call this after commit or rollback to reset tracking state.

Source

pub fn refresh<T: Model + Serialize>(&mut self, key: ObjectKey, obj: &T)

Update snapshot after flush (new baseline).

Call this after a successful flush to set the current state as the new baseline.

Source

pub fn len(&self) -> usize

Number of tracked snapshots.

Source

pub fn is_empty(&self) -> bool

Check if there are no snapshots.

Trait Implementations§

Source§

impl Default for ChangeTracker

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more