pub struct Rule {
pub head: RuleHead,
pub body: Vec<Literal>,
}Expand description
Datalog rule: head :- body_1, ..., body_n.
Fields§
§head: RuleHeadWhat the rule concludes.
body: Vec<Literal>Body literals. An empty body represents a fact.
Implementations§
Source§impl Rule
impl Rule
Sourcepub fn try_new(
head: impl Into<RuleHead>,
body: Vec<Literal>,
) -> Result<Self, ProgramValidationError>
pub fn try_new( head: impl Into<RuleHead>, body: Vec<Literal>, ) -> Result<Self, ProgramValidationError>
Construct a standalone rule only when it is safe and stratifiable.
§Errors
Rejects invalid terms, unsafe variables and recursion through negation.
Sourcepub fn literal_count(&self) -> usize
pub fn literal_count(&self) -> usize
Number of body literals, counting each aggregate’s inner body.
Sourcepub fn positive(head: impl Into<RuleHead>, body: Vec<Atom>) -> Self
pub fn positive(head: impl Into<RuleHead>, body: Vec<Atom>) -> Self
Construct a rule whose body contains only positive literals.
Convenience for the common case — callers that do not need
negation never have to name Literal.
Sourcepub fn new(head: impl Into<RuleHead>, body: Vec<Literal>) -> Self
pub fn new(head: impl Into<RuleHead>, body: Vec<Literal>) -> Self
Construct a rule with an explicit literal body.
Sourcepub fn is_safe(&self) -> bool
pub fn is_safe(&self) -> bool
Returns true when the rule satisfies Datalog¬ safety.
A rule is safe when:
- Every variable appearing in a head atom is bound by some positive
body atom,
Bind, or aggregate export, unless the head quantifies it existentially. Existential variables are unused nowhere and bound nowhere in the body. - Every variable appearing in a negative body literal is bound by
some positive body atom,
Bind, or aggregate export (range restriction — negation-as-failure requires the negated atom to be ground by the time it is evaluated). - Every variable appearing inside a
Literal::Filteris bound by some positive body atom,Bind, or aggregate export — filters guard bindings, they do not produce them. - Every variable inside a
Literal::Bindexpression is bound by an positive body atom, an earlierBind, or an earlier aggregate export, and theBind’s output variable is fresh in that bound set.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Rule
impl<'de> Deserialize<'de> for Rule
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>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Rule
impl StructuralPartialEq for Rule
Auto Trait Implementations§
impl Forget for Rule
impl Freeze for Rulewhere
*const ArcInner<str> is !null: Freeze,
PhantomData<ArcInner<str>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<Term>: Freeze,
PhantomData<Atom>: Freeze,
PhantomData<VariableSymbol>: Freeze,
PhantomData<HeadConjunction>: Freeze,
PhantomData<Literal>: Freeze,
impl Move for Rule
impl RefUnwindSafe for Rule
impl Send for Rule
impl Sync for Rule
impl Unpin for Rule
impl UnsafeUnpin for Rulewhere
*const ArcInner<str> is !null: UnsafeUnpin,
PhantomData<ArcInner<str>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Term>: UnsafeUnpin,
PhantomData<Atom>: UnsafeUnpin,
PhantomData<VariableSymbol>: UnsafeUnpin,
PhantomData<HeadConjunction>: UnsafeUnpin,
PhantomData<Literal>: UnsafeUnpin,
impl UnwindSafe for Rulewhere
Arc<str>: UnwindSafe,
RawVecInner: UnwindSafe,
BoxRaw<Atom>: UnwindSafe,
BoxRaw<BuiltinFilter>: UnwindSafe,
BoxRaw<BindExpr>: UnwindSafe,
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