use crate::{expr::Expr, function::FunctionContext, value::Value, Result};
#[derive(Debug, Clone, PartialEq)]
pub struct Rule {
pub(super) name: String,
description: Option<String>,
expr: Expr,
}
impl Rule {
pub fn new(
name: impl Into<String>,
description: impl Into<Option<String>>,
expr: Expr,
) -> Self {
Self {
name: name.into(),
description: description.into(),
expr,
}
}
pub async fn evaluate<'a>(&self, context: &mut FunctionContext<'a>, facts: &Value) -> Outcome {
Outcome {
value: self.expr.evaluate(context, facts).await,
rule: &self.name,
}
}
pub fn name(&self) -> &str {
&self.name
}
pub fn description(&self) -> Option<&str> {
self.description.as_deref()
}
}
pub struct Outcome<'a> {
pub value: Result<Value>,
pub rule: &'a str,
}