pub struct RuleStore { /* private fields */ }Expand description
A named collection of RuleDefinition objects loaded from disk.
Rules can be loaded from a JSON array file or a YAML array file. After loading, individual rules are retrieved by name.
§JSON file format
[
{ "name": "rule-a", "logic": { "...": "..." } },
{ "name": "rule-b", "version": "1.0.0", "logic": { "...": "..." } }
]§YAML file format
- name: rule-a
logic:
">": [{"var": "score"}, 700]Implementations§
Source§impl RuleStore
impl RuleStore
Sourcepub fn from_json_file(path: impl AsRef<Path>) -> Result<Self, RuleEngineError>
pub fn from_json_file(path: impl AsRef<Path>) -> Result<Self, RuleEngineError>
Load rules from a JSON file (array of RuleDefinition objects).
Sourcepub fn from_json_str(json: &str) -> Result<Self, RuleEngineError>
pub fn from_json_str(json: &str) -> Result<Self, RuleEngineError>
Load rules from a JSON string (array of RuleDefinition objects).
Sourcepub fn get(&self, name: &str) -> Option<&RuleDefinition>
pub fn get(&self, name: &str) -> Option<&RuleDefinition>
Retrieve a rule by name.
Sourcepub fn all(&self) -> &[RuleDefinition]
pub fn all(&self) -> &[RuleDefinition]
All rules in the store.
Sourcepub fn insert(&mut self, rule: RuleDefinition)
pub fn insert(&mut self, rule: RuleDefinition)
Add a rule to the store at runtime.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RuleStore
impl RefUnwindSafe for RuleStore
impl Send for RuleStore
impl Sync for RuleStore
impl Unpin for RuleStore
impl UnsafeUnpin for RuleStore
impl UnwindSafe for RuleStore
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