Struct KnowledgeBase

Source
pub struct KnowledgeBase {
    pub mro: HashMap<Symbol, Vec<u64>>,
    pub inline_queries: Vec<Term>,
    pub resource_blocks: ResourceBlocks,
    /* private fields */
}

Fields§

§mro: HashMap<Symbol, Vec<u64>>

Map of class name -> MRO list where the MRO list is a list of class instance IDs

§inline_queries: Vec<Term>§resource_blocks: ResourceBlocks

Resource block bookkeeping.

Implementations§

Source§

impl KnowledgeBase

Source

pub fn new() -> Self

Source

pub fn new_id(&self) -> u64

Return a monotonically increasing integer ID.

Wraps around at 52 bits of precision so that it can be safely coerced to an IEEE-754 double-float (f64).

Source

pub fn id_counter(&self) -> Counter

Source

pub fn temp_prefix(name: &str) -> String

Generate a temporary variable prefix from a variable name.

Source

pub fn gensym(&self, prefix: &str) -> Symbol

Generate a new symbol.

Source

pub fn add_rule(&mut self, rule: Rule)

Source

pub fn validate_rules(&self) -> Vec<Diagnostic>

Source

pub fn get_rules(&self) -> &HashMap<Symbol, GenericRule>

Source

pub fn get_generic_rule(&self, name: &Symbol) -> Option<&GenericRule>

Source

pub fn add_rule_type(&mut self, rule_type: Rule)

Source

pub fn register_constant( &mut self, name: Symbol, value: Term, ) -> PolarResult<()>

Define a constant variable.

Error on attempts to register the “union” types (Actor & Resource) since those types have special meaning in policies that use resource blocks.

Source

pub fn is_constant(&self, name: &Symbol) -> bool

Return true if a constant with the given name has been defined.

Source

pub fn get_registered_constants(&self) -> &Bindings

Getter for constants map without exposing it for mutation.

Source

pub fn get_registered_class(&self, class: &Term) -> PolarResult<&Term>

Source

pub fn add_mro(&mut self, name: Symbol, mro: Vec<u64>) -> PolarResult<()>

Add the Method Resolution Order (MRO) list for a registered class. The mro argument is a list of the instance_id associated with a registered class.

Source

pub fn clear_rules(&mut self)

Source

pub fn rewrite_shorthand_rules(&mut self) -> Vec<PolarError>

Source

pub fn create_resource_specific_rule_types(&mut self) -> PolarResult<()>

Source

pub fn is_union(&self, maybe_union: &Term) -> bool

Source

pub fn get_union_members(&self, union: &Term) -> &HashSet<Term>

Source

pub fn has_rules(&self) -> bool

Trait Implementations§

Source§

impl Default for KnowledgeBase

Source§

fn default() -> KnowledgeBase

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.