pub enum Guard {
Spec(Pred),
Custom(Arc<dyn Fn(&FlowCtx<'_>) -> bool + Send + Sync>),
}Expand description
A boolean predicate over (state, marking) — the only predicate type.
Use the constructors (Guard::is_true, Guard::captured,
Guard::called_ok, …) for the serializable closed atoms, or
Guard::custom for a bespoke closure (not serializable).
Variants§
Spec(Pred)
A serializable predicate built from the closed atom set.
Custom(Arc<dyn Fn(&FlowCtx<'_>) -> bool + Send + Sync>)
A code-only escape hatch. Not serializable.
Implementations§
Source§impl Guard
impl Guard
Sourcepub fn eq(key: impl Into<String>, value: impl Into<Value>) -> Self
pub fn eq(key: impl Into<String>, value: impl Into<Value>) -> Self
State key equals the given JSON value.
Sourcepub fn captured<I, S>(fields: I) -> Self
pub fn captured<I, S>(fields: I) -> Self
All of the given state keys are present (extracted slots).
Sourcepub fn decided(question: impl Into<String>) -> Self
pub fn decided(question: impl Into<String>) -> Self
The caller’s current turn settles the declared question question: a
boolean answered yes, a choice that picked an option, or a score. See
decided.
Sourcepub fn decided_no(question: impl Into<String>) -> Self
pub fn decided_no(question: impl Into<String>) -> Self
The caller’s current turn answers the boolean question no (or a
choice picks “none of these”).
Sourcepub fn decided_is(
question: impl Into<String>,
option: impl Into<String>,
) -> Self
pub fn decided_is( question: impl Into<String>, option: impl Into<String>, ) -> Self
The caller’s current turn picks option for the choice question.
Sourcepub fn decided_at_least(question: impl Into<String>, bound: f64) -> Self
pub fn decided_at_least(question: impl Into<String>, bound: f64) -> Self
The score question is at least bound.
Sourcepub fn decided_at_most(question: impl Into<String>, bound: f64) -> Self
pub fn decided_at_most(question: impl Into<String>, bound: f64) -> Self
The score question is at most bound.
Sourcepub fn resolved(name: impl AsRef<str>) -> Self
pub fn resolved(name: impl AsRef<str>) -> Self
True once an orchestrated agent named name has produced a result
(its {name}:result state key is set). Pairs with the
orchestration call/dispatch/background.
Sourcepub fn all(guards: impl IntoIterator<Item = Guard>) -> Self
pub fn all(guards: impl IntoIterator<Item = Guard>) -> Self
Conjunction.
If every input is a serializable atom, the result is a serializable
Pred::All. If any input is a Guard::custom, the result is itself a
custom guard that evaluates the conjunction at runtime — the custom guard
is never silently dropped (it merely makes the combinator
non-serializable, which surfaces as an error only if you try to serialize
the flow).
Sourcepub fn any(guards: impl IntoIterator<Item = Guard>) -> Self
pub fn any(guards: impl IntoIterator<Item = Guard>) -> Self
Disjunction.
Mirrors Guard::all: custom inputs are preserved as a runtime closure
rather than erased.
Sourcepub fn describe(&self) -> String
pub fn describe(&self) -> String
This guard as a short prose clause, for telling a model what a refusal is waiting on.
A refusal that names only the tool leaves the model to guess the
precondition, and a wrong guess is indistinguishable from a wrong model:
in the governed collections evaluation, record_promise_to_pay was
refused with “not available in the current step”, and the model — with
nothing else to go on — decided it must need to re-verify the caller and
asked for the card digits it had already checked.
Sourcepub fn custom(f: impl Fn(&FlowCtx<'_>) -> bool + Send + Sync + 'static) -> Self
pub fn custom(f: impl Fn(&FlowCtx<'_>) -> bool + Send + Sync + 'static) -> Self
A bespoke closure over (state, marking). Not serializable.
Sourcepub fn possible(&self, ctx: &FlowCtx<'_>) -> Option<bool>
pub fn possible(&self, ctx: &FlowCtx<'_>) -> Option<bool>
Evaluate the guard as the caller’s next words could leave it: every
decided atom unknown, since its question is asked again about each
turn. Some(value) when no decision can change the outcome, None
when one could make the guard hold or fail. A custom guard is
evaluated as it stands.
Sourcepub fn eval_state(&self, state: &State) -> bool
pub fn eval_state(&self, state: &State) -> bool
Evaluate against state alone, with an empty Marking.
For contexts outside a governed flow (phase transitions, watcher
conditions) where no marking exists: called_ok/done atoms evaluate
false there — a validator should reject them in such positions.
Sourcepub fn explain_trace(&self, ctx: &FlowCtx<'_>) -> GuardTrace
pub fn explain_trace(&self, ctx: &FlowCtx<'_>) -> GuardTrace
Evaluate to a GuardTrace — the predicate tree with per-node truth
values. A Guard::custom yields a single opaque node.
Sourcepub fn state_keys(&self) -> BTreeSet<String>
pub fn state_keys(&self) -> BTreeSet<String>
The state keys this guard reads (is_true/is_set/eq/captured
atoms). A custom guard reads nothing that can be named, so it
reports none.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Guard
impl<'de> Deserialize<'de> for Guard
Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
Source§impl JsonSchema for Guard
impl JsonSchema for Guard
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref keyword. Read moreSource§fn schema_name() -> String
fn schema_name() -> String
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Auto Trait Implementations§
impl !RefUnwindSafe for Guard
impl !UnwindSafe for Guard
impl Freeze for Guard
impl Send for Guard
impl Sync for Guard
impl Unpin for Guard
impl UnsafeUnpin for Guard
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,
§impl<T> Conv for T
impl<T> Conv for T
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.