Skip to main content

Change

Enum Change 

Source
#[non_exhaustive]
pub enum Change<'a, E> { Created { after: &'a mut E, }, Updated { before: &'a E, after: &'a mut E, }, Transitioned { before: &'a E, after: &'a mut E, transition: String, field: String, from: Option<String>, to: Option<String>, }, Deleted { before: &'a E, hard: bool, }, Restored { entity: &'a E, }, }
Expand description

One row change, as a write hook sees it.

In WriteHooks::before the row to be stored is mutable: a hook may fill a derived field. In WriteHooks::after it is the row as stored. Matching on it needs a wildcard arm; kinds may be added.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Created

A row is created.

Fields

§after: &'a mut E

The row to store, or as stored.

§

Updated

A row is changed by a generic write (PUT, PATCH or their bulk forms).

Fields

§before: &'a E

The row as it was read.

§after: &'a mut E

The row to store, or as stored.

§

Transitioned

A row is moved by a state-machine verb.

Fields

§before: &'a E

The row as it was read.

§after: &'a mut E

The row to store, or as stored.

§transition: String

The verb (close, approve).

§field: String

The state field that moved, in the serialized naming (status).

§from: Option<String>

The state the row left.

§to: Option<String>

The state the row entered.

§

Deleted

A row is deleted: soft-deleted, or removed for good when hard.

Fields

§before: &'a E

The row as it was read.

§hard: bool

Whether the row is removed for good (from the trash) rather than moved to it.

§

Restored

A soft-deleted row is restored.

Fields

§entity: &'a E

The row: as it was in the trash before the write, as restored after it.

Implementations§

Source§

impl<'a, E> Change<'a, E>

Source

pub fn kind(&self) -> ChangeKind

Which kind of change this is.

Source

pub fn before(&self) -> Option<&E>

The row as it was read before the write; None for a create.

Source

pub fn after(&self) -> Option<&E>

The row the write stores; None for a delete.

Source

pub fn subject(&self) -> &E

The row an event of this change is about: what the write stores, or the row deleted.

Source§

impl<'a, E> Change<'a, E>

Source

pub fn after_mut(&mut self) -> Option<&mut E>

The row to store, mutable: for a hook that fills a field before the write. None for a delete or a restore, which store no new row.

Source

pub fn before_and_after_mut(&mut self) -> Option<(&E, &mut E)>

The row as it was read and the row to store, the second mutable: for a hook that fills a field of an update from what it was. None unless the change is an update.

Source§

impl<'a, E: Serialize> Change<'a, E>

Source

pub fn field_changed(&self, name: &str) -> bool

Whether the serialized field name differs between the row before and after. A create changes every field it sets (non-null); a delete changes none.

Trait Implementations§

Source§

impl<'a, E: Debug> Debug for Change<'a, E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, E> !UnwindSafe for Change<'a, E>

§

impl<'a, E> Freeze for Change<'a, E>

§

impl<'a, E> RefUnwindSafe for Change<'a, E>

§

impl<'a, E> Send for Change<'a, E>

§

impl<'a, E> Sync for Change<'a, E>

§

impl<'a, E> Unpin for Change<'a, E>

§

impl<'a, E> UnsafeUnpin for Change<'a, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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: 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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