RuleNode

Struct RuleNode 

Source
pub struct RuleNode {
    pub id: String,
    pub condition: String,
}

Fields§

§id: String§condition: String

Implementations§

Source§

impl RuleNode

Source

pub fn new(id: impl Into<String>, condition: impl Into<String>) -> Self

Examples found in repository?
examples/advanced_flow.rs (lines 22-25)
6async fn main() -> anyhow::Result<()> {
7    // Initialize tracing
8    tracing_subscriber::fmt()
9        .with_max_level(tracing::Level::DEBUG)
10        .init();
11
12    println!("=== Rust Logic Graph - Advanced Flow Example ===");
13    println!("Scenario: User Analytics Report Generation with Permission Checks\n");
14
15    // Load graph definition
16    let def = GraphIO::load_from_file("examples/advanced_flow.json")?;
17
18    // Create custom executor with specific node configurations
19    let mut executor = Executor::new();
20
21    // Register nodes with custom logic
22    executor.register_node(Box::new(RuleNode::new(
23        "validate_input",
24        "user_id > 0"
25    )));
26
27    executor.register_node(Box::new(DBNode::new(
28        "fetch_user_data",
29        "SELECT * FROM users WHERE id = ?"
30    )));
31
32    executor.register_node(Box::new(RuleNode::new(
33        "check_permissions",
34        "user_role == \"admin\""
35    )));
36
37    executor.register_node(Box::new(DBNode::new(
38        "query_analytics",
39        "SELECT * FROM analytics WHERE user_id = ?"
40    )));
41
42    executor.register_node(Box::new(AINode::new(
43        "generate_report",
44        "Generate comprehensive analytics report from data"
45    )));
46
47    executor.register_node(Box::new(AINode::new(
48        "send_notification",
49        "Send notification to user about report status"
50    )));
51
52    // Create graph and set initial context
53    let mut graph = Graph::new(def);
54
55    // Simulate input data
56    graph.context.data.insert("user_id".to_string(), json!(1001));
57    graph.context.data.insert("user_role".to_string(), json!("admin"));
58
59    println!("Initial Context:");
60    println!("  - user_id: 1001");
61    println!("  - user_role: admin\n");
62
63    // Execute the graph
64    println!("Starting advanced flow execution...\n");
65    executor.execute(&mut graph).await?;
66
67    // Display results
68    println!("\n=== Execution Results ===");
69    println!("\nContext Data:");
70    for (key, value) in &graph.context.data {
71        if key.ends_with("_result") {
72            println!("  {}: {}", key, serde_json::to_string_pretty(&value)?);
73        }
74    }
75
76    println!("\n=== Flow Complete ===");
77    Ok(())
78}
More examples
Hide additional examples
examples/grl_graph_flow.rs (lines 22-25)
6async fn main() -> anyhow::Result<()> {
7    // Initialize tracing
8    tracing_subscriber::fmt()
9        .with_max_level(tracing::Level::INFO)
10        .init();
11
12    println!("=== Rust Logic Graph - GRL Integration Example ===");
13    println!("Scenario: Loan Application with Advanced GRL Rules\n");
14
15    // Load graph definition
16    let def = GraphIO::load_from_file("examples/grl_graph_flow.json")?;
17
18    // Create custom executor with GRL-powered nodes
19    let mut executor = Executor::new();
20
21    // Input validation with GRL
22    executor.register_node(Box::new(RuleNode::new(
23        "input_validation",
24        "loan_amount > 0 && loan_amount <= 1000000"
25    )));
26
27    // Fetch customer data
28    executor.register_node(Box::new(DBNode::new(
29        "fetch_customer",
30        "SELECT * FROM customers WHERE id = ?"
31    )));
32
33    // Risk assessment with complex GRL rules
34    executor.register_node(Box::new(RuleNode::new(
35        "risk_assessment",
36        "credit_score >= 600 && income >= loan_amount * 3"
37    )));
38
39    // Fraud detection AI
40    executor.register_node(Box::new(AINode::new(
41        "fraud_detection",
42        "Analyze transaction patterns for fraud indicators"
43    )));
44
45    // Final approval decision
46    executor.register_node(Box::new(RuleNode::new(
47        "approval_decision",
48        "risk_score < 50 && fraud_score < 30"
49    )));
50
51    // Notification
52    executor.register_node(Box::new(AINode::new(
53        "notification",
54        "Generate approval/rejection notification email"
55    )));
56
57    // Create graph with initial context
58    let mut graph = Graph::new(def);
59
60    // Set application data
61    graph.context.data.insert("loan_amount".to_string(), json!(50000));
62    graph.context.data.insert("credit_score".to_string(), json!(720));
63    graph.context.data.insert("income".to_string(), json!(180000));
64    graph.context.data.insert("customer_id".to_string(), json!(12345));
65
66    println!("Application Data:");
67    println!("  Loan Amount: $50,000");
68    println!("  Credit Score: 720");
69    println!("  Annual Income: $180,000");
70    println!("  Customer ID: 12345\n");
71
72    // Execute the graph
73    println!("Processing loan application through GRL-powered workflow...\n");
74    executor.execute(&mut graph).await?;
75
76    // Display results
77    println!("\n=== Application Results ===\n");
78
79    if let Some(validation) = graph.context.data.get("input_validation_result") {
80        println!("✓ Input Validation: {}", validation);
81    }
82
83    if let Some(customer) = graph.context.data.get("fetch_customer_result") {
84        println!("✓ Customer Data Retrieved");
85    }
86
87    if let Some(risk) = graph.context.data.get("risk_assessment_result") {
88        println!("✓ Risk Assessment: {}", risk);
89    }
90
91    if let Some(fraud) = graph.context.data.get("fraud_detection_result") {
92        println!("✓ Fraud Detection Completed");
93    }
94
95    if let Some(decision) = graph.context.data.get("approval_decision_result") {
96        println!("✓ Approval Decision: {}", decision);
97    }
98
99    println!("\n=== GRL-Powered Workflow Complete ===");
100
101    // Demonstrate standalone GRL engine
102    println!("\n=== Bonus: Advanced GRL Rules ===\n");
103
104    let mut grl_engine = RuleEngine::new();
105
106    let advanced_rules = r#"
107rule "HighValueLoan" salience 100 {
108    when
109        loan_amount > 100000 && credit_score < 750
110    then
111        requires_manual_review = true;
112        approval_tier = "senior";
113}
114
115rule "StandardApproval" salience 50 {
116    when
117        loan_amount <= 100000 && credit_score >= 650
118    then
119        auto_approve = true;
120        approval_tier = "standard";
121}
122
123rule "RiskMitigation" salience 25 {
124    when
125        debt_to_income_ratio > 0.4
126    then
127        requires_collateral = true;
128        interest_rate_adjustment = 1.5;
129}
130"#;
131
132    grl_engine.add_grl_rule(advanced_rules)?;
133
134    println!("Advanced GRL rules loaded:");
135    println!("  - High Value Loan Review");
136    println!("  - Standard Approval Process");
137    println!("  - Risk Mitigation Measures");
138
139    println!("\n✅ All systems operational with rust-rule-engine integration!");
140
141    Ok(())
142}

Trait Implementations§

Source§

impl Clone for RuleNode

Source§

fn clone(&self) -> RuleNode

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RuleNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Node for RuleNode

Source§

fn id(&self) -> &str

Source§

fn node_type(&self) -> NodeType

Source§

fn run<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 mut Context, ) -> Pin<Box<dyn Future<Output = RuleResult> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more