Skip to main content

Change

Enum Change 

Source
pub enum Change<M> {
    Create(M),
    Update {
        before: M,
        after: M,
    },
    Delete(Vec<M>),
    Restore(Vec<M>),
    ForceDelete(Vec<M>),
    Action {
        name: &'static str,
        records: Vec<M>,
    },
    HeaderAction {
        name: &'static str,
    },
    Attach {
        owner: M,
        relation: String,
        key: String,
    },
    Detach {
        owner: M,
        relation: String,
        keys: Vec<String>,
    },
}
Expand description

What one write of a resource changed: the mutation and the rows it wrote.

Resource::before_commit receives it inside the write’s transaction and Resource::after_commit once the transaction commits.

The enum is exhaustive on purpose: an audit hook that matches every variant stops compiling when a new kind of write appears, instead of skipping it.

A create or an update that also links or unlinks records through a many-to-many form field reports the record only: the links are not in M. Read them through the hook’s executor when an audit needs them; the relation table’s own writes report as Change::Attach and Change::Detach.

A save that also writes a Relation::has_one’s child reports the owner here, and the child to the related resource’s hooks, as its own pages would.

Variants§

§

Create(M)

A create wrote this row.

§

Update

An update wrote after over before, the snapshot the handler loaded and authorized inside the transaction. A submission that names no field writes nothing and still reports an update, with before == after.

Fields

§before: M
§after: M
§

Delete(Vec<M>)

A delete or a bulk delete removed these rows, or trashed them on a soft-deleting resource, as they stood before the delete.

§

Restore(Vec<M>)

A restore brought back these trashed rows, as they stood before it: their deleted-at column still holds the time they were trashed.

§

ForceDelete(Vec<M>)

A force delete removed these trashed rows for good, as they stood before it.

§

Action

The custom Action name ran on these rows, as the handler loaded them before it ran.

Fields

§name: &'static str
§records: Vec<M>
§

HeaderAction

The HeaderAction name ran, on no record: its audit can record who ran it, through the context, and which action.

Fields

§name: &'static str
§

Attach

A many-to-many relation’s table linked owner to the related record key names.

relation is the owner’s #[has_many(via = ..)] field and key the related resource’s record key, as its URLs spell it whatever spelling the request posted. Attaching a linked record writes nothing and still reports the attach.

Fields

§owner: M
§relation: String
§

Detach

A many-to-many relation’s table unlinked owner from the related records keys name, as their URLs spell them.

Fields

§owner: M
§relation: String
§keys: Vec<String>

Implementations§

Source§

impl<M> Change<M>

Source

pub fn records(&self) -> &[M]

The rows of this resource the change names: the created row and the updated row as the write left them, the deleted, restored or force-deleted rows and the rows an action ran on as they stood before it, the owner of an attach or a detach, and none for a header action.

Source

pub fn is_action<A, R>(&self) -> bool
where A: Action<R>, R: Resource<Model = M>,

Whether the change is a run of the custom action A.

It compares against A::NAME, as Ability::is_action does, and a type that is not an action of a resource over M does not compile. R is inferred when A is an action of one resource.

fn published(change: &Change<Post>) -> usize {
    if change.is_action::<Publish, _>() {
        change.records().len()
    } else {
        0
    }
}
Source

pub fn is_header_action<A: HeaderAction>(&self) -> bool

Whether the change is a run of the header action A.

It compares against A::NAME, as Ability::is_header_action does.

fn audited(change: &Change<Post>) -> bool {
    !change.is_header_action::<RecountTags>()
}

Trait Implementations§

Source§

impl<M: Clone> Clone for Change<M>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<M: Debug> Debug for Change<M>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<M: Eq> Eq for Change<M>

Source§

impl<M: PartialEq> PartialEq for Change<M>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<M: PartialEq> StructuralPartialEq for Change<M>

Auto Trait Implementations§

§

impl<M> Forget for Change<M>

§

impl<M> Freeze for Change<M>
where M: Freeze, Vec<M>: Freeze,

§

impl<M> RefUnwindSafe for Change<M>

§

impl<M> Send for Change<M>
where M: Send, Vec<M>: Send,

§

impl<M> Sync for Change<M>
where M: Sync, Vec<M>: Sync,

§

impl<M> Unpin for Change<M>
where M: Unpin, Vec<M>: Unpin,

§

impl<M> UnsafeUnpin for Change<M>
where M: UnsafeUnpin, Vec<M>: UnsafeUnpin,

§

impl<M> UnwindSafe for Change<M>
where M: UnwindSafe, Vec<M>: 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> AnyEq for T
where T: Any + PartialEq,

Source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

Source§

fn as_any(&self) -> &(dyn Any + 'static)

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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