pub struct RuleDefinition {
pub name: String,
pub logic: Value,
pub version: Option<String>,
pub description: Option<String>,
pub tags: Vec<String>,
pub required_context_keys: Vec<String>,
}Expand description
A rule definition with metadata for decision systems.
This wraps a JSON-Logic rule blob with identifying information: name, version, tags, and optional description. The metadata is carried alongside the rule for governance, audit, and traceability.
Fields§
§name: StringUnique name identifying this rule.
logic: ValueThe JSON-Logic rule blob.
version: Option<String>Optional semantic version for this rule.
description: Option<String>Optional human-readable description.
Tags for categorization and filtering.
required_context_keys: Vec<String>Context keys that must be present for this rule to execute.
Used by validate_context to enforce schema contracts.
Implementations§
Source§impl RuleDefinition
impl RuleDefinition
Sourcepub fn new(name: impl Into<String>, logic: Value) -> Self
pub fn new(name: impl Into<String>, logic: Value) -> Self
Create a new rule definition with a name and logic.
Sourcepub fn with_version(self, version: impl Into<String>) -> Self
pub fn with_version(self, version: impl Into<String>) -> Self
Builder: set the version.
Sourcepub fn with_description(self, description: impl Into<String>) -> Self
pub fn with_description(self, description: impl Into<String>) -> Self
Builder: set the description.
Builder: set tags.
Sourcepub fn with_required_keys(self, keys: Vec<String>) -> Self
pub fn with_required_keys(self, keys: Vec<String>) -> Self
Builder: declare which context keys are required.
Sourcepub fn validate_context(&self, context: &Value) -> Result<(), ValidationError>
pub fn validate_context(&self, context: &Value) -> Result<(), ValidationError>
Validate that a parsed JSON context object contains all required keys.
Returns Ok(()) when all keys are present, or a ValidationError
listing every missing key.
Trait Implementations§
Source§impl Clone for RuleDefinition
impl Clone for RuleDefinition
Source§fn clone(&self) -> RuleDefinition
fn clone(&self) -> RuleDefinition
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RuleDefinition
impl Debug for RuleDefinition
Source§impl<'de> Deserialize<'de> for RuleDefinition
impl<'de> Deserialize<'de> for RuleDefinition
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>,
Source§impl PartialEq for RuleDefinition
impl PartialEq for RuleDefinition
Source§impl Serialize for RuleDefinition
impl Serialize for RuleDefinition
impl StructuralPartialEq for RuleDefinition
Auto Trait Implementations§
impl Freeze for RuleDefinition
impl RefUnwindSafe for RuleDefinition
impl Send for RuleDefinition
impl Sync for RuleDefinition
impl Unpin for RuleDefinition
impl UnsafeUnpin for RuleDefinition
impl UnwindSafe for RuleDefinition
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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