pub struct TriggerPredicate {
pub field: String,
pub eq: Option<Value>,
pub changed_to: Option<Value>,
}Expand description
A single declarative field/transition predicate on an after:mutation trigger (#597).
The when condition that decides whether a function fires, evaluated by the
dispatcher against the built payload before any runtime spins.
Deliberately small: a field plus exactly one operator — eq (state) or
changed_to (transition). Anything richer stays guest code; this is a dispatch
filter, not a rules engine. A list of predicates is a conjunction (all must
hold); an empty list always fires (back-compat).
{ "field": "status", "changed_to": "approved" } // UPDATE-only transition test
{ "field": "kind", "eq": "standard" } // state test (INSERT + UPDATE)Fields§
§field: StringThe field (a JSON key in the row image) to test.
eq: Option<Value>State test: the field currently equals this value. Evaluated on the
after-image (INSERT/UPDATE) or, for a DELETE, the pre-image. An absent field
never equals a value (missing ⇒ false).
changed_to: Option<Value>Transition test (UPDATE-only): the field changed to this value —
old.field != v && new.field == v. A DELETE (no after-image) never matches;
changed_to on a non-update trigger is a load error.
Implementations§
Source§impl TriggerPredicate
impl TriggerPredicate
Sourcepub fn matches(&self, old: Option<&Value>, new: Option<&Value>) -> bool
pub fn matches(&self, old: Option<&Value>, new: Option<&Value>) -> bool
Evaluate this predicate against a row’s old/new images.
eq: the current image (new, oroldon a DELETE) hasfield == v. Missing field ⇒false.changed_to:old.field != v && new.field == v.
A predicate with neither operator set (rejected at load) never matches.
Sourcepub fn validate(&self, operation: Option<&str>) -> Result<(), String>
pub fn validate(&self, operation: Option<&str>) -> Result<(), String>
Validate the predicate at load time against the trigger’s operation
(insert/update/delete, or None for all).
§Errors
- Neither
eqnorchanged_toset, or both set (exactly one operator). changed_toon a non-updatetrigger (a transition needs a before + after).
Trait Implementations§
Source§impl Clone for TriggerPredicate
impl Clone for TriggerPredicate
Source§fn clone(&self) -> TriggerPredicate
fn clone(&self) -> TriggerPredicate
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TriggerPredicate
impl Debug for TriggerPredicate
Source§impl<'de> Deserialize<'de> for TriggerPredicate
impl<'de> Deserialize<'de> for TriggerPredicate
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for TriggerPredicate
Source§impl PartialEq for TriggerPredicate
impl PartialEq for TriggerPredicate
Source§impl Serialize for TriggerPredicate
impl Serialize for TriggerPredicate
impl StructuralPartialEq for TriggerPredicate
Auto Trait Implementations§
impl Freeze for TriggerPredicate
impl RefUnwindSafe for TriggerPredicate
impl Send for TriggerPredicate
impl Sync for TriggerPredicate
impl Unpin for TriggerPredicate
impl UnsafeUnpin for TriggerPredicate
impl UnwindSafe for TriggerPredicate
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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