pub struct Graph {
pub def: GraphDef,
pub context: Context,
}Fields§
§def: GraphDef§context: ContextImplementations§
Source§impl Graph
impl Graph
Sourcepub fn new(def: GraphDef) -> Self
pub fn new(def: GraphDef) -> Self
Examples found in repository?
examples/parallel_execution.rs (line 308)
290async fn analyze_and_execute(def: GraphDef) -> anyhow::Result<()> {
291 // Create parallel executor
292 let mut executor = ParallelExecutor::new(ParallelConfig {
293 max_concurrent: 10,
294 verbose: true,
295 });
296
297 // Register nodes
298 for node_id in def.nodes.keys() {
299 let node: Box<dyn Node> = Box::new(RuleNode::new(node_id, "true"));
300 executor.register_node(node);
301 }
302
303 // Analyze parallelism
304 let stats = executor.get_parallelism_stats(&def)?;
305 stats.print_summary();
306
307 // Execute the graph
308 let mut graph = Graph::new(def);
309 let start = Instant::now();
310 executor.execute(&mut graph).await?;
311 let duration = start.elapsed();
312
313 println!("Execution completed in {:?}", duration);
314
315 Ok(())
316}More examples
examples/simple_flow.rs (line 22)
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 - Simple Flow Example ===\n");
13
14 // Load graph definition from JSON
15 let def = GraphIO::load_from_file("examples/simple_flow.json")?;
16 println!("Loaded graph with {} nodes and {} edges\n",
17 def.nodes.len(),
18 def.edges.len()
19 );
20
21 // Create graph
22 let mut graph = Graph::new(def);
23
24 // Execute the graph
25 println!("Starting graph execution...\n");
26 Orchestrator::execute_graph(&mut graph).await?;
27
28 // Display final context
29 println!("\n=== Final Context ===");
30 for (key, value) in &graph.context.data {
31 println!("{}: {}", key, value);
32 }
33
34 println!("\n=== Execution Complete ===");
35 Ok(())
36}examples/advanced_flow.rs (line 53)
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}examples/grl_graph_flow.rs (line 58)
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}Auto Trait Implementations§
impl Freeze for Graph
impl RefUnwindSafe for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnwindSafe for Graph
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