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.
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.
HeaderAction
The HeaderAction name ran, on no record: its audit can record
who ran it, through the context, and which action.
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.
Detach
A many-to-many relation’s table unlinked owner from the related records keys name, as
their URLs spell them.
Implementations§
Source§impl<M> Change<M>
impl<M> Change<M>
Sourcepub fn records(&self) -> &[M]
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.
Sourcepub fn is_action<A, R>(&self) -> bool
pub fn is_action<A, R>(&self) -> bool
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
}
}Sourcepub fn is_header_action<A: HeaderAction>(&self) -> bool
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§
impl<M: Eq> Eq for Change<M>
impl<M: PartialEq> StructuralPartialEq for Change<M>
Auto Trait Implementations§
impl<M> Forget for Change<M>
impl<M> Freeze for Change<M>
impl<M> RefUnwindSafe for Change<M>
impl<M> Send for Change<M>
impl<M> Sync for Change<M>
impl<M> Unpin for Change<M>
impl<M> UnsafeUnpin for Change<M>
impl<M> UnwindSafe for Change<M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.