Skip to main content

Tracked

Struct Tracked 

Source
pub struct Tracked<E: Entity> { /* private fields */ }
Expand description

A loaded Entity that remembers its original column values so save persists only what changed. Deref targets the inner E, so reads and field mutations go straight through.

Implementations§

Source§

impl<E: Entity> Tracked<E>

Source

pub fn new(entity: E) -> Self

Wrap an in-hand entity; its current column values become the baseline.

Source

pub async fn load<X, V>(exec: &X, pk: V) -> Result<Option<Self>>
where X: Executor, V: Into<Value>,

Load pk’s row and wrap it for tracking. None when no row matches.

Source

pub fn changes(&self) -> Vec<(&'static str, Value)>

The columns whose value differs from the baseline (the dirty set), in the entity’s declared column order.

Source

pub fn is_dirty(&self) -> bool

Whether any tracked column has changed since load / last save.

Source

pub async fn save<X: Executor>(&mut self, exec: &X) -> Result<u64>

Persist the dirty columns with a single UPDATE … WHERE pk = ?, returning rows affected. A no-op returning 0 when nothing changed. On success the baseline is reset to the saved state, so a later save writes only newer changes (and an immediate re-save is a no-op).

Source

pub fn get(&self) -> &E

Borrow the inner entity (also available through Deref).

Source

pub fn into_inner(self) -> E

Unwrap, discarding tracking state.

Trait Implementations§

Source§

impl<E: Entity> Deref for Tracked<E>

Source§

type Target = E

The resulting type after dereferencing.
Source§

fn deref(&self) -> &E

Dereferences the value.
Source§

impl<E: Entity> DerefMut for Tracked<E>

Source§

fn deref_mut(&mut self) -> &mut E

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<E> Freeze for Tracked<E>
where E: Freeze,

§

impl<E> RefUnwindSafe for Tracked<E>
where E: RefUnwindSafe,

§

impl<E> Send for Tracked<E>
where E: Send,

§

impl<E> Sync for Tracked<E>
where E: Sync,

§

impl<E> Unpin for Tracked<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for Tracked<E>
where E: UnsafeUnpin,

§

impl<E> UnwindSafe for Tracked<E>
where E: UnwindSafe,

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, 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.