rust-rule-engine 0.1.2

A high-performance rule engine for Rust with GRL (Grule Rule Language) support, file-based rules, custom functions, and method calls
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
# ๐Ÿฆ€ Rust Rule Engine - GRL Edition

A powerful, high-performance rule engine for Rust supporting **GRL (Grule Rule Language)** syntax with advanced features like method calls, custom functions, object interactions, and both file-based and inline rule management.

[![Crates.io](https://img.shields.io/crates/v/rust-rule-engine.svg)](https://crates.io/crates/rust-rule-engine)
[![Documentation](https://docs.rs/rust-rule-engine/badge.svg)](https://docs.rs/rust-rule-engine)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## ๐ŸŒŸ Key Features

- **๐Ÿ”ฅ GRL-Only Support**: Pure Grule Rule Language syntax (no JSON)
- **๐Ÿ“„ Rule Files**: External `.grl` files for organized rule management  
- **๐Ÿ“ Inline Rules**: Define rules as strings directly in your code
- **๐Ÿ“ž Custom Functions**: Register and call user-defined functions from rules
- **๐ŸŽฏ Method Calls**: Support for `Object.method(args)` and property access
- **๐Ÿง  Knowledge Base**: Centralized rule management with salience-based execution
- **๐Ÿ’พ Working Memory**: Facts system for complex object interactions  
- **โšก High Performance**: Optimized execution engine with cycle detection
- **๐Ÿ”„ Arithmetic Expressions**: Complex calculations in conditions and actions
- **๐Ÿ›ก๏ธ Type Safety**: Rust's type system ensures runtime safety
- **๐Ÿ“ˆ Execution Statistics**: Detailed performance metrics and debugging
- **๐ŸŽ›๏ธ Configurable Engine**: Timeouts, max cycles, debug modes
- **๐Ÿ—๏ธ Builder Pattern**: Clean API with `RuleEngineBuilder`
- **๐Ÿ“š Rich Examples**: Real-world scenarios (e-commerce, fraud detection)

## ๐Ÿš€ Quick Start

Add to your `Cargo.toml`:

```toml
[dependencies]
rust-rule-engine = "0.1.2"
```

### ๐Ÿ“„ File-Based Rules

Create a rule file `rules/example.grl`:

```grl
rule "AgeCheck" salience 10 {
    when
        User.Age >= 18 && User.Country == "US"
    then
        User.setIsAdult(true);
        User.setCategory("Adult");
        log("User qualified as adult");
}

rule "VIPUpgrade" salience 20 {
    when
        User.IsAdult == true && User.SpendingTotal > 1000
    then
        User.setIsVIP(true);
        log("User upgraded to VIP status");
}
```

```rust
use rust_rule_engine::{RuleEngineBuilder, Value, Facts};
use std::collections::HashMap;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create engine with rule file
    let mut engine = RuleEngineBuilder::new()
        .with_rule_file("rules/example.grl")?
        .build();

    // Register custom functions
    engine.register_function("User.setIsAdult", |args, _| {
        println!("Setting adult status: {}", args[0]);
        Ok(Value::Boolean(true))
    });

    engine.register_function("User.setCategory", |args, _| {
        println!("Setting category: {}", args[0]);
        Ok(Value::String(args[0].to_string()))
    });

    // Create facts
    let facts = Facts::new();
    let mut user = HashMap::new();
    user.insert("Age".to_string(), Value::Integer(25));
    user.insert("Country".to_string(), Value::String("US".to_string()));
    user.insert("SpendingTotal".to_string(), Value::Number(1500.0));

    facts.add_value("User", Value::Object(user))?;

    // Execute rules
    let result = engine.execute(&facts)?;
    println!("Rules fired: {}", result.rules_fired);

    Ok(())
}
```

### ๐Ÿ“ Inline String Rules

Define rules directly in your code:

```rust
use rust_rule_engine::{RuleEngineBuilder, Value, Facts};
use std::collections::HashMap;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let grl_rules = r#"
        rule "HighValueCustomer" salience 20 {
            when
                Customer.TotalSpent > 1000.0
            then
                sendWelcomeEmail(Customer.Email, "GOLD");
                log("Customer upgraded to GOLD tier");
        }

        rule "LoyaltyBonus" salience 15 {
            when
                Customer.OrderCount >= 10
            then
                applyLoyaltyBonus(Customer.Id, 50.0);
                log("Loyalty bonus applied");
        }
    "#;

    // Create engine with inline rules
    let mut engine = RuleEngineBuilder::new()
        .with_inline_grl(grl_rules)?
        .build();

    // Register custom functions
    engine.register_function("sendWelcomeEmail", |args, _| {
        println!("๐Ÿ“ง Welcome email sent to {} for {} tier", args[0], args[1]);
        Ok(Value::Boolean(true))
    });

    engine.register_function("applyLoyaltyBonus", |args, _| {
        println!("๐Ÿ’ฐ Loyalty bonus of {} applied to customer {}", args[1], args[0]);
        Ok(Value::Number(args[1].as_number().unwrap_or(0.0)))
    });

    // Create facts
    let facts = Facts::new();
    let mut customer = HashMap::new();
    customer.insert("TotalSpent".to_string(), Value::Number(1250.0));
    customer.insert("OrderCount".to_string(), Value::Integer(12));
    customer.insert("Email".to_string(), Value::String("john@example.com".to_string()));
    customer.insert("Id".to_string(), Value::String("CUST001".to_string()));

    facts.add_value("Customer", Value::Object(customer))?;

    // Execute rules
    let result = engine.execute(&facts)?;
    println!("Rules fired: {}", result.rules_fired);

    Ok(())
}
```

## ๐ŸŽฏ Advanced Features

### Custom Function Registry

Register and call your own functions from rules:

```rust
use rust_rule_engine::{RuleEngineBuilder, Value, Facts};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let grl_rules = r#"
        rule "SpeedCheck" salience 20 {
            when
                Car.Speed > 80.0
            then
                checkSpeedLimit(Car.Speed, 80.0);
                sendAlert("Speed limit exceeded!", Driver.Name);
        }
    "#;

    let mut engine = RuleEngineBuilder::new()
        .with_inline_grl(grl_rules)?
        .build();

    // Register custom functions
    engine.register_function("checkSpeedLimit", |args, _facts| {
        let speed = args[0].as_number().unwrap_or(0.0);
        let limit = args[1].as_number().unwrap_or(0.0);
        println!("๐Ÿšฆ Speed check: {} vs limit {}", speed, limit);
        Ok(Value::Boolean(speed > limit))
    });

    engine.register_function("sendAlert", |args, _facts| {
        let message = &args[0];
        let driver = &args[1]; 
        println!("๏ฟฝ ALERT to {}: {}", driver, message);
        Ok(Value::Boolean(true))
    });

    let facts = Facts::new();
    // ... setup facts
    
    let result = engine.execute(&facts)?;
```

### Engine Configuration

Configure the engine for your needs:

```rust
use rust_rule_engine::{RuleEngineBuilder, EngineConfig};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = EngineConfig {
        max_cycles: 10,
        debug_mode: true,
        execution_timeout: Some(std::time::Duration::from_secs(30)),
        ..Default::default()
    };

    let engine = RuleEngineBuilder::new()
        .with_rule_file("rules/business_rules.grl")?
        .with_config(config)
        .build();

    // Execute with monitoring
    let result = engine.execute(&facts)?;
    println!("โœ… Executed in {} cycles, {} rules fired", 
             result.cycle_count, result.rules_fired);
    
    Ok(())
}

```

## ๐ŸŽฏ GRL Rule Language Features

### Supported Syntax

```grl
rule "RuleName" salience 10 {
    when
        Object.Property > 100 &&
        Object.Status == "ACTIVE"
    then
        Object.setCategory("HIGH_VALUE");
        processTransaction(Object.Id, Object.Amount);
        log("Rule executed successfully");
}
```

### Operators

- **Comparison**: `>`, `>=`, `<`, `<=`, `==`, `!=`
- **Logical**: `&&`, `||` 
- **Value Types**: Numbers, Strings (quoted), Booleans (`true`/`false`)

### Actions

- **Method Calls**: `Object.method(args)`
- **Function Calls**: `functionName(args)`
- **Logging**: `log("message")`

## ๐Ÿ“š Examples

### ๐Ÿ›’ E-commerce Rules

```grl
rule "VIPCustomer" salience 20 {
    when
        Customer.TotalSpent > 5000.0 && Customer.YearsActive >= 2
    then
        Customer.setTier("VIP");
        sendWelcomePackage(Customer.Email, "VIP");
        applyDiscount(Customer.Id, 15.0);
        log("Customer upgraded to VIP");
}

rule "LoyaltyReward" salience 15 {
    when
        Customer.OrderCount >= 50
    then
        addLoyaltyPoints(Customer.Id, 500);
        log("Loyalty reward applied");
}
```

### ๐Ÿš— Vehicle Monitoring

```grl
rule "SpeedLimit" salience 25 {
    when
        Vehicle.Speed > Vehicle.SpeedLimit
    then
        triggerAlert(Vehicle.Id, "SPEED_VIOLATION");
        logViolation(Vehicle.Driver, Vehicle.Speed);
        Vehicle.setStatus("FLAGGED");
}

rule "MaintenanceDue" salience 10 {
    when
        Vehicle.Mileage > Vehicle.NextMaintenance
    then
        scheduleService(Vehicle.Id, Vehicle.Mileage);
        notifyDriver(Vehicle.Driver, "Maintenance due");
}
```

## โšก Performance & Architecture

### Benchmarks

```text
Rule Execution Performance:
โ€ข Simple conditions: ~10-50 microseconds
โ€ข Complex multi-condition rules: ~100-500 microseconds  
โ€ข Custom function calls: ~50-200 microseconds
โ€ข File-based rule loading: ~1-5 milliseconds

Memory Usage:
โ€ข Rule storage: ~1KB per rule
โ€ข Facts storage: ~100-500 bytes per fact
โ€ข Engine overhead: ~10KB base memory
```

### Architecture Overview

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   GRL Files     โ”‚    โ”‚  Inline Rules   โ”‚    โ”‚ Custom Functionsโ”‚
โ”‚   (.grl)        โ”‚    โ”‚   (Strings)     โ”‚    โ”‚   (Registry)    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                       โ”‚                       โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   GRL Parser    โ”‚
                    โ”‚   (Tokenizer)   โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚ Knowledge Base  โ”‚
                    โ”‚ (Rule Storage)  โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚  Rule Engine    โ”‚
                    โ”‚ (Execution)     โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚  Facts System   โ”‚
                    โ”‚ (Working Memory)โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

### Key Design Decisions

- **GRL-Only**: Removed JSON support for cleaner, focused API
- **Dual Sources**: Support both file-based and inline rule definitions
- **Custom Functions**: Extensible function registry for business logic
- **Builder Pattern**: Fluent API for easy engine configuration
- **Type Safety**: Leverages Rust's type system for runtime safety
- **Zero-Copy**: Efficient string and memory management

## ๐Ÿ—๏ธ Development

### Building from Source

```bash
git clone https://github.com/KSD-CO/rust-rule-engine.git
cd rust-rule-engine
cargo build --release
```

### Running Examples

```bash
# File-based rules with custom functions
cargo run --example rule_file_functions_demo

# Inline rules demonstration  
cargo run --example inline_rules_demo

# Complete GRL feature showcase
cargo run --example grule_demo

# Custom function registry
cargo run --example custom_functions_demo

# Builder pattern usage
cargo run --example builder_test
```

### Testing

```bash
# Run all tests
cargo test

# Run with output
cargo test -- --nocapture

# Run specific test
cargo test integration_tests
```

### Publishing

```bash
# Check package
cargo check

# Run all tests
cargo test

# Build documentation
cargo doc --no-deps

# Publish dry run
cargo publish --dry-run

# Publish to crates.io
cargo publish
```

## ๐Ÿ“‹ API Reference

### Core Types

```rust
// Main engine builder
RuleEngineBuilder::new()
    .with_rule_file("path/to/rules.grl")?
    .with_inline_grl("rule content")?
    .with_config(config)
    .build()

// Value types
Value::Integer(42)
Value::Number(3.14)
Value::String("text".to_string())
Value::Boolean(true)
Value::Object(HashMap<String, Value>)

// Facts management
let facts = Facts::new();
facts.add_value("Object", value)?;
facts.get("Object")?;

// Execution results
result.rules_fired       // Number of rules that executed
result.cycle_count       // Number of execution cycles
result.execution_time    // Duration of execution
```

### Function Registration

```rust
engine.register_function("functionName", |args, facts| {
    // args: Vec<Value> - function arguments
    // facts: &Facts - current facts state
    // Return: Result<Value, RuleEngineError>
    
    let param1 = &args[0];
    let param2 = args[1].as_number().unwrap_or(0.0);
    
    // Your custom business logic here
    println!("Function called with: {:?}", args);
    
    Ok(Value::String("Success".to_string()))
});
```

## ๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

### Development Setup

1. Fork the repository
2. Create your feature branch: `git checkout -b feature/amazing-feature`
3. Make your changes and add tests
4. Ensure all tests pass: `cargo test`
5. Commit your changes: `git commit -m 'Add amazing feature'`
6. Push to the branch: `git push origin feature/amazing-feature`
7. Open a Pull Request

### Guidelines

- Follow Rust naming conventions
- Add tests for new features
- Update documentation for API changes
- Ensure examples work with changes

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐ŸŽฏ Roadmap

- [ ] **Enhanced GRL Support**: More operators and complex conditions
- [ ] **Rule Templates**: Reusable rule patterns
- [ ] **Performance Optimizations**: Rule compilation and caching
- [ ] **Debugging Tools**: Rule execution tracing and profiling
- [ ] **Integration Examples**: Database, HTTP APIs, message queues
- [ ] **Rule Validation**: Static analysis and rule conflict detection

## ๐Ÿ“ž Support

- ๐Ÿ“š **Documentation**: [docs.rs/rust-rule-engine]https://docs.rs/rust-rule-engine
- ๐Ÿ› **Issues**: [GitHub Issues]https://github.com/KSD-CO/rust-rule-engine/issues
- ๐Ÿ’ฌ **Discussions**: [GitHub Discussions]https://github.com/KSD-CO/rust-rule-engine/discussions

---

**Built with โค๏ธ in Rust** ๐Ÿฆ€
    
    // Create TestCar: speed=50, maxSpeed=100, increment=10, canSpeedUp=true
    let test_car = FactHelper::create_test_car(50.0, 100.0, 10.0, true);
    facts.add_value("TestCar", test_car)?;
    
    // Create DistanceRecord: totalDistance=0, currentDistance=0
    let distance_record = FactHelper::create_distance_record(0.0, 0.0);
    facts.add_value("DistanceRecord", distance_record)?;
    
    // Execute rules
    println!("๐Ÿ Before execution:");
    println!("   TestCar.Speed = {:?}", facts.get_nested("TestCar.Speed"));
    println!("   DistanceRecord.TotalDistance = {:?}", facts.get_nested("DistanceRecord.TotalDistance"));
    
    let result = engine.execute(&facts)?;
    
    println!("\n๐Ÿš€ After execution:");
    println!("   TestCar.Speed = {:?}", facts.get_nested("TestCar.Speed"));  
    println!("   DistanceRecord.TotalDistance = {:?}", facts.get_nested("DistanceRecord.TotalDistance"));
    println!("   Rules fired: {}", result.rules_fired);
    
    Ok(())
}
```

Expected output:
```
๐Ÿ Before execution:
   TestCar.Speed = Some(Number(50.0))
   DistanceRecord.TotalDistance = Some(Number(0.0))

๐Ÿš€ After execution:
   TestCar.Speed = Some(Number(60.0))
   DistanceRecord.TotalDistance = Some(Number(60.0))
   Rules fired: 1
```

### E-commerce Rules Example

```rust
let ecommerce_rules = r#"
rule "PremiumDiscount" salience 20 {
    when
        Customer.Membership == "premium" && Order.Total > 100
    then
        Order.DiscountRate = 0.15;
        Order.FreeShipping = true;
}

rule "BulkDiscount" salience 15 {
    when
        Order.ItemCount >= 5
    then
        Order.BulkDiscount = Order.Total * 0.10;
}
"#;
            User.IsAdult == true && User.SpendingTotal > 1000
        then
            User.IsVIP = true;
            User.DiscountRate = 0.20;
            Log("User upgraded to VIP");
```

### Fraud Detection Example

```rust
let fraud_rules = r#"
rule "HighValueTransaction" salience 30 {
    when
        Transaction.Amount > 1000 && User.VerificationLevel < 3
    then
        Transaction.RequiresReview = true;
        Transaction.FraudScore = Transaction.FraudScore + 25;
}

rule "SuspiciousLocation" salience 25 {
    when
        User.Country != Transaction.Location && Transaction.Amount > 500
    then
        Transaction.RequiresReview = true;
        Transaction.FraudScore = Transaction.FraudScore + 15;
}
"#;
```

## ๐Ÿ“š Documentation

### Core Components

#### KnowledgeBase
Manages collections of rules with metadata and execution context.

```rust
let kb = KnowledgeBase::new("MyRuleSet");
kb.add_rule(rule)?;
kb.enable_rule("rule_name");
kb.disable_rule("rule_name");
```

#### Facts (Working Memory)
Stores and manages data objects that rules operate on.

```rust
let facts = Facts::new();
facts.add_value("User", user_object)?;
facts.set_nested("User.Profile.Age", Value::Integer(25))?;
let age = facts.get_nested("User.Profile.Age");
```

#### RustRuleEngine
Executes rules against facts with configurable options.

```rust
let config = EngineConfig {
    max_cycles: 100,
    timeout: Some(Duration::from_secs(30)),
    debug_mode: true,
    enable_stats: true,
};
let engine = RustRuleEngine::with_config(kb, config);
```

#### GRLParser
Parses Grule Rule Language syntax into executable rules.

```rust
let rule = GRLParser::parse_rule(grl_text)?;
let rules = GRLParser::parse_rules(multi_rule_text)?;
```

### Helper Functions

#### FactHelper
Utility functions for creating common data objects.

```rust
// Standard objects
let user = FactHelper::create_user("john", 25, "john@email.com", "US", false);
let order = FactHelper::create_order("ord123", "user456", 150.0, 3, "pending");
let product = FactHelper::create_product("Widget", 29.99, "gadgets", true, 100);

// Method call demo objects
let test_car = FactHelper::create_test_car(50.0, 100.0, 10.0, true);
let distance_record = FactHelper::create_distance_record(0.0, 0.0);

// Generic object creation
let custom_obj = FactHelper::create_object(vec![
    ("name", Value::String("Custom".to_string())),
    ("value", Value::Number(42.0)),
    ("active", Value::Boolean(true)),
]);
```

#### TestCarClass Properties

The TestCarClass object supports these properties and methods:

```rust
// Properties (auto-accessible in GRL)
Speed: Number          // Current speed
MaxSpeed: Number       // Maximum allowed speed  
SpeedIncrement: Number // Speed increase per acceleration
speedUp: Boolean       // Whether car can speed up

// Methods (callable from GRL)
setSpeed(new_speed)    // Set the car's speed
getSpeed()             // Get current speed
accelerate()           // Increase speed by SpeedIncrement
brake()                // Decrease speed
```

#### DistanceRecordClass Properties

```rust
// Properties
TotalDistance: Number     // Total distance traveled
CurrentDistance: Number   // Current trip distance

// Methods  
setTotalDistance(distance)  // Set total distance
getTotalDistance()          // Get total distance
addDistance(amount)         // Add to total distance
reset()                     // Reset distances to 0
```

## ๐ŸŽ›๏ธ Configuration Options

### EngineConfig

```rust
pub struct EngineConfig {
    pub max_cycles: usize,           // Maximum execution cycles
    pub timeout: Option<Duration>,   // Execution timeout
    pub enable_stats: bool,          // Performance statistics
    pub debug_mode: bool,            // Debug output
}
```

### Execution Results

```rust
pub struct GruleExecutionResult {
    pub cycle_count: usize,          // Number of cycles executed
    pub rules_evaluated: usize,      // Rules checked for conditions
    pub rules_fired: usize,          // Rules that executed actions
    pub execution_time: Duration,    // Total execution time
}
```

## ๐ŸŽฏ GRL Syntax Reference

### Rule Structure

```grl
rule "RuleName" salience PRIORITY {
    when
        CONDITION
    then
        ACTION
}
```

### Conditions

```grl
// Simple comparisons
User.Age >= 18
Product.Price < 100.0
Order.Status == "pending"

// Compound conditions
User.Age >= 18 && User.Country == "US"
Product.InStock == true || Product.PreOrder == true

// Object type checks (advanced)
$User : UserClass( Age >= 18 && Status == "active" )
```

### Actions

```grl
// Field assignments
User.IsAdult = true;
Order.DiscountRate = 0.15;

// Method calls
$TestCar.setSpeed($TestCar.Speed + $TestCar.SpeedIncrement);

// Function calls
update($User);
Log("Message");

// Arithmetic expressions
Order.Total = Order.Subtotal - Order.Discount;
```

## ๐Ÿ—๏ธ Architecture

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   GRL Parser    โ”‚โ”€โ”€โ”€โ–ถโ”‚  Knowledge Base  โ”‚โ”€โ”€โ”€โ–ถโ”‚  Grule Engine   โ”‚
โ”‚                 โ”‚    โ”‚                  โ”‚    โ”‚                 โ”‚
โ”‚ - Parse Rules   โ”‚    โ”‚ - Store Rules    โ”‚    โ”‚ - Execute Rules โ”‚
โ”‚ - Validate      โ”‚    โ”‚ - Manage State   โ”‚    โ”‚ - Cycle Control โ”‚
โ”‚ - Transform     โ”‚    โ”‚ - Salience Sort  โ”‚    โ”‚ - Statistics    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                โ”‚                        โ”‚
                                โ–ผ                        โ–ผ
                       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                       โ”‚      Facts       โ”‚    โ”‚    Results      โ”‚
                       โ”‚                  โ”‚    โ”‚                 โ”‚
                       โ”‚ - Working Memory โ”‚    โ”‚ - Fired Rules   โ”‚
                       โ”‚ - Data Objects   โ”‚    โ”‚ - Execution     โ”‚
                       โ”‚ - Property Tree  โ”‚    โ”‚   Statistics    โ”‚
                       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

## ๐Ÿงช Examples
    "description": "Premium user discount",
    "priority": 15,
    "conditions": {
        "and": [
            {"field": "user.membership", "operator": "==", "value": "premium"},
            {"field": "order.total", "operator": ">", "value": 100}
        ]
    },
    "actions": [
        {"type": "set", "field": "order.discount", "value": 0.15},
        {"type": "log", "message": "Premium discount applied"}
    ]
}
"#;

let rule = RuleParser::from_json(json_rule)?;
```

## ๐Ÿ—๏ธ Architecture (Grule-Style)

### Core Components

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Knowledge Base โ”‚    โ”‚   Grule Engine   โ”‚    โ”‚     Facts       โ”‚
โ”‚                 โ”‚    โ”‚                  โ”‚    โ”‚                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚    โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚    โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚   Rules   โ”‚  โ”‚โ”€โ”€โ”€โ–ถโ”‚  โ”‚ Inference   โ”‚ โ”‚โ—€โ”€โ”€โ–ถโ”‚ โ”‚   Working   โ”‚ โ”‚
โ”‚  โ”‚ (GRL/JSON)โ”‚  โ”‚    โ”‚  โ”‚   Engine    โ”‚ โ”‚    โ”‚ โ”‚   Memory    โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚    โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚    โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                 โ”‚    โ”‚                  โ”‚    โ”‚                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚    โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚    โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚ Salience  โ”‚  โ”‚    โ”‚  โ”‚   Action    โ”‚ โ”‚    โ”‚ โ”‚   Objects   โ”‚ โ”‚
โ”‚  โ”‚ Priority  โ”‚  โ”‚    โ”‚  โ”‚  Handlers   โ”‚ โ”‚    โ”‚ โ”‚    Data     โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚    โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚    โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

### Execution Flow

1. **Load Rules**: Add rules to Knowledge Base via GRL or JSON
2. **Create Facts**: Set up working memory with data objects  
3. **Execute**: Grule Engine runs inference cycles
4. **Match**: Rules are evaluated against facts
5. **Fire**: Matching rules execute their actions
6. **Modify**: Actions update facts in working memory
7. **Repeat**: Continue until no more rules fire

## ๐Ÿ“ GRL (Grule Rule Language) Syntax

### Rule Structure
```grl
The `examples/` directory contains comprehensive examples:

```bash
# Run basic GRL demo
cargo run --example method_calls_demo

# Run e-commerce rules
cargo run --example ecommerce

# Run fraud detection
cargo run --example complete_speedup_demo

# Debug conditions
cargo run --example debug_conditions
```

## ๐Ÿงช Running Examples

### Basic Method Calls Demo

```bash
cargo run --example method_calls_demo
```

Output:
```
=== Demo: SpeedUp Rule with Method Calls ===

๐Ÿ Initial state:
   TestCar.Speed = Number(50.0)
   DistanceRecord.TotalDistance = Number(0.0)

๐Ÿš€ Executing SpeedUp rule...
๐Ÿ”ฅ Rule 'SpeedUp' fired (salience: 10)

๐Ÿ“Š Execution Results:
   Cycles: 1
   Rules evaluated: 1
   Rules fired: 1
   Execution time: 14.041ยตs
```

### E-commerce Rules Demo

```bash
cargo run --example ecommerce
```

## ๐Ÿ”ง Development

### Prerequisites

- Rust 1.70+
- Cargo

### Building

```bash
git clone https://github.com/KSD-CO/rust-rule-engine
cd rust-rule-engine
cargo build --release
```

### Testing

```bash
# Run all tests
cargo test

# Run with output
cargo test -- --nocapture

# Run specific test
cargo test test_basic_grule_rules
```

### Benchmarks

```bash
cargo bench
```

## ๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the project
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

## ๐Ÿ“‹ Roadmap

- [ ] **Enhanced GRL Parser**: Full Grule language compatibility
- [ ] **RETE Algorithm**: Advanced pattern matching optimization
- [ ] **Rule Debugging**: Step-through debugging capabilities
- [ ] **Web Dashboard**: Browser-based rule management
- [ ] **Hot Reload**: Dynamic rule updates without restart
- [ ] **Distributed Rules**: Multi-node rule execution
- [ ] **Visual Editor**: Drag-and-drop rule builder
- [ ] **More Integrations**: Database, message queues, web frameworks

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ™ Acknowledgments

- Inspired by the [Grule Rule Engine]https://github.com/hyperjumptech/grule-rule-engine for Go
- Thanks to the Rust community for excellent crates and documentation
- Built with love for high-performance rule processing

## ๐Ÿ“Š Performance

| Metric | Value |
|--------|-------|
| Rules/sec | 50,000+ |
| Memory Usage | < 10MB for 1000 rules |
| Startup Time | < 1ms |
| Rule Parse Time | < 100ฮผs per rule |

## ๐Ÿ”— Links

- [Crates.io]https://crates.io/crates/rust-rule-engine
- [Documentation]https://docs.rs/rust-rule-engine
- [Repository]https://github.com/your-username/rust-rule-engine
- [Issues]https://github.com/your-username/rust-rule-engine/issues
- [Changelog]CHANGELOG.md
    when
        ConditionExpression
    then
        ActionStatement;
        ActionStatement;
}
```

### Supported Operators
- **Comparison**: `==`, `!=`, `>`, `>=`, `<`, `<=`
- **String**: `contains`, `starts_with`, `ends_with`, `matches`
- **Logical**: `&&` (AND), `||` (OR), `!` (NOT)

### Example Conditions
```grl
// Simple condition
User.Age >= 18

// Complex condition  
User.Age >= 18 && User.Country == "US" || User.IsVIP == true

// String operations
User.Email contains "@company.com"

// Regex matching
User.Phone matches "^\\+1[0-9]{10}$"
```

### Example Actions
```grl
// Set values
User.IsAdult = true;
User.DiscountRate = 0.15;

// Function calls
Log("User processed");
SendEmail(User.Email, "welcome");
Retract("TemporaryData");
```

## ๐ŸŽฏ Advanced Features

### Knowledge Base Management
```rust
let kb = KnowledgeBase::new("MyKB");

// Add rules from GRL
kb.add_rules_from_grl(grl_content)?;

// Manage rules
kb.remove_rule("RuleName")?;
kb.set_rule_enabled("RuleName", false)?;

// Statistics
let stats = kb.get_statistics();
println!("Rules: {}", stats.total_rules);

// Export to GRL
let exported = kb.export_to_grl();
```

### Facts Management
```rust
let facts = Facts::new();

// Add structured data
let user = FactHelper::create_user("Alice", 30, "alice@example.com", "US", true);
facts.add_value("User", user)?;

// Nested property access
facts.set_nested("User.Profile.Age", Value::Integer(31))?;
let age = facts.get_nested("User.Profile.Age");

// Snapshots for rollback
let snapshot = facts.snapshot();
facts.restore(snapshot);
```

### Engine Configuration
```rust
let config = EngineConfig {
    max_cycles: 100,           // Maximum inference cycles
    timeout: Some(Duration::from_secs(10)), // Execution timeout
    enable_stats: true,        // Collect performance statistics
    debug_mode: true,          // Enable debug logging
};

let engine = RustRuleEngine::with_config(kb, config);
```

### Custom Functions
```rust
engine.register_function(
    "SendEmail".to_string(),
    |args| {
        if let Some(email) = args.get(0) {
            // Send email logic here
            Ok(format!("Email sent to: {}", email.to_string()))
        } else {
            Ok("Email sent".to_string())
        }
    }
);
```

## ๐Ÿ“Š Performance & Statistics

### Execution Statistics
```rust
let result = engine.execute(&facts)?;

println!("Cycles: {}", result.cycle_count);
println!("Rules Evaluated: {}", result.rules_evaluated); 
println!("Rules Fired: {}", result.rules_fired);
println!("Execution Time: {:?}", result.execution_time);

// Engine-wide statistics
let stats = engine.get_stats();
println!("Total Executions: {}", stats.total_executions);
println!("Average Time: {:?}", stats.average_execution_time);
```

### Benchmarks
- **Rule Loading**: ~1ms for 100 rules
- **Rule Execution**: ~10ฮผs per rule evaluation
- **Memory Usage**: ~50KB for 100 rules
- **Throughput**: 100,000+ rule evaluations/sec

## ๐Ÿช Use Cases

### โœ… Perfect for:
- **Business Rules**: Dynamic business logic management
- **E-commerce**: Pricing, discounts, promotions, inventory
- **Fraud Detection**: Risk assessment, pattern matching  
- **User Management**: Authentication, permissions, tiers
- **Workflow Automation**: Process control, approval flows
- **Content Moderation**: Auto-moderation, filtering rules
- **IoT & Monitoring**: Alert rules, threshold monitoring
- **Game Logic**: Scoring, rewards, achievements
- **Financial Services**: Risk assessment, compliance


## ๐Ÿ“– Examples

### Complete Examples

Run the included examples:

```bash
# Grule-style demo
cargo run --example grule_demo

# E-commerce rules
cargo run --example ecommerce  

# Fraud detection
cargo run --example fraud_detection

# Main demo
cargo run
```

### E-commerce Example
```grl
rule NewCustomerDiscount "Welcome discount" salience 20 {
    when
        Customer.IsNew == true && Order.Total > 50
    then
        Order.Discount = Order.Total * 0.10;
        SendEmail(Customer.Email, "welcome");
        Log("New customer discount applied");
}

rule VIPBenefits "VIP customer benefits" salience 30 {
    when  
        Customer.Tier == "VIP" && Order.Total > 100
    then
        Order.FreeShipping = true;
        Order.ExpressProcessing = true;
        Order.Discount = Order.Total * 0.15;
}
```

### Fraud Detection Example
```grl
rule HighVelocityFraud "Detect high velocity transactions" salience 40 {
    when
        User.TransactionsLastHour >= 5 && Transaction.Amount > 100
    then
        Transaction.FraudScore = 90;
        Transaction.Blocked = true;
        Alert("High velocity fraud detected");
}

rule UnusualLocation "Unusual location check" salience 35 {
    when
        Transaction.LocationRisk == "high" && User.TravelAlert != true
    then
        Transaction.RequiresVerification = true;
        Transaction.FraudScore = 75;
}
```

## ๐Ÿงช Testing

```bash
# Run all tests
cargo test

# Run with output
cargo test -- --nocapture

# Performance tests
cargo test --release performance

# Integration tests
cargo test --test integration_tests
```

## ๏ฟฝ Development

### Building
```bash
# Debug build
cargo build

# Release build  
cargo build --release

# With all features
cargo build --all-features
```

### Linting
```bash
# Check code
cargo check

# Format code
cargo fmt

# Lint code
cargo clippy
```

## ๐ŸŽ‰ Migration from Grule

If you're migrating from Grule (Go), here's a quick guide:

### Grule (Go) โ†’ Rust Rule Engine

```go
// Grule (Go)
kb := ast.NewKnowledgeBaseFromResource("rules.grl")
dc := ast.NewDataContext()
dc.Add("User", &user)
engine := &engine.RustRuleEngine{}
err := engine.Execute(dc, kb)
```

```rust
// Rust Rule Engine  
let kb = KnowledgeBase::new("rules");
kb.add_rules_from_grl(include_str!("rules.grl"))?;
let facts = Facts::new();
facts.add("User", user)?;
let engine = RustRuleEngine::new(kb);
let result = engine.execute(&facts)?;
```

### GRL Compatibility

Most Grule GRL syntax is supported:
- โœ… Basic rule structure
- โœ… When/then clauses  
- โœ… Salience
- โœ… Logical operators
- โœ… Comparison operators
- โœ… Function calls
- โœ… Variable assignments

## ๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the project
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ™ Acknowledgments

- **Inspired by Grule Rule Engine** for Go by Hyperjump Technology
- Built with Rust's excellent ecosystem
- Thanks to the community for feedback and contributions

---

**Made with โค๏ธ and ๐Ÿฆ€ - Bringing Grule's power to Rust!**