pub struct RuleConstraint { /* private fields */ }Expand description
Compiled representation of a single TLExpr constraint.
Two forms coexist:
- Eager table (
allow_set) — populated when the constraint compiles to a finite predicate list over a user-supplied vocabulary mapper. This path is the fast path and is used by the hard/soft masks. - Fallback pass-through — used when the expression hit an unsupported
variant. In that case
RuleConstraint::evaluatereturnsConstraintVerdict::SoftPenalty(0.0)and the decoder behaves as if no constraint was present.
Implementations§
Source§impl RuleConstraint
impl RuleConstraint
Sourcepub fn compile<M>(expr: TLExpr, mapper: M) -> RuleGuidedResult<Self>
pub fn compile<M>(expr: TLExpr, mapper: M) -> RuleGuidedResult<Self>
Compile a constraint from a TLExpr and a token → symbol-name mapper.
- If the expression only uses supported variants, the returned
constraint eagerly enumerates allowed symbol names into a
HashSet. - Otherwise, the constraint is still constructed but evaluates to a
no-op (soft-penalty of zero). This makes the decoder forward-
compatible: new
TLExprvariants don’t break existing call sites.
Sourcepub fn evaluate(
&self,
prefix: &[TokenId],
candidate: TokenId,
) -> ConstraintVerdict
pub fn evaluate( &self, prefix: &[TokenId], candidate: TokenId, ) -> ConstraintVerdict
Evaluate the constraint against (prefix, candidate).
prefix is the token sequence already committed to the beam; it is
not used by the current allow-list compiler but is part of the contract
so stateful constraints (e.g. “no token X after token Y”) remain
implementable without an API break — see extend_tlexpr_support.
Sourcepub fn allow_set(&self) -> Option<&HashSet<String>>
pub fn allow_set(&self) -> Option<&HashSet<String>>
Read-only access to the compiled allow-list, if any.
Sourcepub fn is_supported(&self) -> bool
pub fn is_supported(&self) -> bool
true when the constraint was compiled against a supported subset of
TLExpr. false means the constraint is a no-op.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RuleConstraint
impl !RefUnwindSafe for RuleConstraint
impl Send for RuleConstraint
impl Sync for RuleConstraint
impl Unpin for RuleConstraint
impl UnsafeUnpin for RuleConstraint
impl !UnwindSafe for RuleConstraint
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
Mutably borrows from an owned value. Read more
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>
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 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>
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