rust-rule-engine 1.20.1

A blazing-fast Rust rule engine with RETE algorithm, backward chaining inference, and GRL (Grule Rule Language) syntax. Features: forward/backward chaining, pattern matching, unification, O(1) rule indexing, TMS, expression evaluation, method calls, streaming with Redis state backend, watermarking, and custom functions. Production-ready for business rules, expert systems, real-time stream processing, and decision automation.
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
# Installation Guide

> **Version:** 1.11.0
> **Last Updated:** December 10, 2024

Complete installation guide for Rust Rule Engine.

---

## ๐Ÿ“‹ Requirements

- **Rust:** 1.70.0 or higher
- **Cargo:** Latest stable version

Check your Rust version:
```bash
rustc --version
cargo --version
```

Need to install Rust? โ†’ [https://rustup.rs/](https://rustup.rs/)

---

## ๐Ÿš€ Quick Installation

### Option 1: Basic Installation

Add to your `Cargo.toml`:

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

### Option 2: With Features

```toml
[dependencies.rust-rule-engine]
version = "1.11"
features = ["backward-chaining", "streaming"]
```

### Option 3: From Git (Latest Development)

```toml
[dependencies]
rust-rule-engine = { git = "https://github.com/KSD-CO/rust-rule-engine", branch = "main" }
```

---

## ๐ŸŽ›๏ธ Available Features

| Feature | Description | Size Impact | Use Case |
|---------|-------------|-------------|----------|
| **Default** | Forward chaining + RETE | Minimal | Basic rule engine |
| `backward-chaining` | Goal-driven inference | +150KB | Queries & reasoning |
| `streaming` | Complex Event Processing | +100KB | Real-time events |
| `streaming-redis` | Redis state backend | +200KB | Distributed systems |

### Feature Combinations

#### Minimal Setup (Forward Chaining Only)
```toml
[dependencies]
rust-rule-engine = "1.11"
```

**Use for:** Basic business rules, decision automation

#### Full Featured (Everything)
```toml
[dependencies.rust-rule-engine]
version = "1.11"
features = ["backward-chaining", "streaming", "streaming-redis"]
```

**Use for:** Enterprise applications, distributed systems

#### Query & Reasoning
```toml
[dependencies.rust-rule-engine]
version = "1.11"
features = ["backward-chaining"]
```

**Use for:** Diagnostic systems, expert systems

#### Stream Processing
```toml
[dependencies.rust-rule-engine]
version = "1.11"
features = ["streaming"]
```

**Use for:** IoT, real-time analytics, CEP

---

## โœ… Verify Installation

Create `src/main.rs`:

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

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut engine = Engine::new();

    engine.add_rule_from_string(r#"
        rule "Test" {
            when
                X == 1
            then
                Y = 2;
        }
    "#)?;

    let mut facts = Facts::new();
    facts.set("X", Value::Integer(1));

    engine.run(&mut facts)?;

    assert_eq!(facts.get("Y"), Some(&Value::Integer(2)));
    println!("โœ… Installation verified!");

    Ok(())
}
```

Run:
```bash
cargo run
```

**Expected output:**
```
โœ… Installation verified!
```

---

## ๐Ÿ”ง Platform-Specific Notes

### Linux

No additional setup required. Install and go!

```bash
cargo add rust-rule-engine
cargo build
```

### macOS

No additional setup required.

```bash
cargo add rust-rule-engine
cargo build
```

### Windows

Works out of the box. If you encounter issues with Redis features:

```powershell
# Install Visual Studio Build Tools first
# Then:
cargo add rust-rule-engine --features backward-chaining,streaming
cargo build
```

### Docker

```dockerfile
FROM rust:1.75

WORKDIR /app
COPY Cargo.toml Cargo.lock ./
COPY src ./src

RUN cargo build --release --features backward-chaining,streaming

CMD ["./target/release/your-app"]
```

---

## ๐Ÿ“ฆ Optional Dependencies

### For Redis State Backend

```toml
[dependencies.rust-rule-engine]
version = "1.11"
features = ["streaming-redis"]

[dependencies]
redis = "0.27"
tokio = { version = "1.42", features = ["full"] }
```

**Install Redis:**
```bash
# macOS
brew install redis
brew services start redis

# Linux (Ubuntu/Debian)
sudo apt-get install redis-server
sudo systemctl start redis

# Docker
docker run -d -p 6379:6379 redis:latest
```

### For Graph Analysis (Advanced)

```toml
[dependencies]
petgraph = "0.6"  # Used by backward-chaining feature
```

This is automatically included with `backward-chaining` feature.

---

## ๐Ÿ”„ Upgrading from Previous Versions

### From 1.10.x โ†’ 1.11.0

**No breaking changes!** Fully backward compatible.

```bash
# Update Cargo.toml
rust-rule-engine = "1.11"

# Update dependencies
cargo update

# Rebuild
cargo build
```

**New features available:**
- Nested queries in backward chaining
- Query optimization (10-100x speedup)

### From 1.9.x โ†’ 1.10.x

```bash
cargo update
```

**New:** Disjunction (OR) support in queries

### From 1.0.x โ†’ Latest

Review [Migration Guide](../guides/MIGRATION.md) for major version changes.

---

## ๐Ÿ—๏ธ Building from Source

```bash
# Clone repository
git clone https://github.com/KSD-CO/rust-rule-engine
cd rust-rule-engine

# Build with all features
cargo build --all-features --release

# Run tests
cargo test --all-features

# Run examples
cargo run --example basic_usage
```

---

## ๐Ÿงช Development Setup

### For Contributors

```bash
# Clone and setup
git clone https://github.com/KSD-CO/rust-rule-engine
cd rust-rule-engine

# Install development dependencies
cargo install cargo-watch
cargo install cargo-tarpaulin

# Run in development mode with auto-reload
cargo watch -x "run --example basic_usage"

# Run tests with coverage
cargo tarpaulin --all-features
```

### Recommended Tools

```bash
# Code formatting
cargo install rustfmt

# Linting
cargo install clippy

# Documentation
cargo doc --open --all-features
```

---

## ๐Ÿ“Š Binary Size Optimization

### Minimal Binary

```toml
[profile.release]
opt-level = "z"     # Optimize for size
lto = true          # Link-time optimization
codegen-units = 1   # Better optimization
strip = true        # Strip symbols
```

**Result:** ~2MB binary (forward chaining only)

### With All Features

**Result:** ~4MB binary (includes backward-chaining + streaming)

---

## ๐Ÿ› Troubleshooting Installation

### Issue: "Can't find rust-rule-engine"

```bash
# Ensure you're using the correct version
cargo update
cargo clean
cargo build
```

### Issue: "Feature not found"

Check that you're using version 1.11+:
```toml
rust-rule-engine = "1.11"
```

### Issue: Redis compilation error

Install Redis separately or disable the feature:
```toml
features = ["backward-chaining", "streaming"]
# Remove "streaming-redis" if not needed
```

### Issue: Out of memory during compilation

```bash
# Reduce parallel jobs
cargo build -j 2
```

### Still Having Issues?

- ๐Ÿ“– [Troubleshooting Guide]../guides/TROUBLESHOOTING.md
- ๐Ÿ’ฌ [GitHub Discussions]https://github.com/KSD-CO/rust-rule-engine/discussions
- ๐Ÿ› [Report Bug]https://github.com/KSD-CO/rust-rule-engine/issues

---

## ๐ŸŽฏ Next Steps

**โœ… Installed?** โ†’ [Quick Start Guide](QUICK_START.md)

**๐Ÿ“š Learn Concepts** โ†’ [Basic Concepts](CONCEPTS.md)

**๐Ÿ”จ Build Something** โ†’ [First Rules Tutorial](FIRST_RULES.md)

**๐Ÿ“– API Reference** โ†’ [API Documentation](../api-reference/API_REFERENCE.md)

---

## ๐Ÿ“„ License & Support

- **License:** MIT
- **Repository:** [github.com/KSD-CO/rust-rule-engine]https://github.com/KSD-CO/rust-rule-engine
- **Documentation:** [docs.rs/rust-rule-engine]https://docs.rs/rust-rule-engine
- **Crate:** [crates.io/crates/rust-rule-engine]https://crates.io/crates/rust-rule-engine

---

## Navigation

๐Ÿ“š **[Documentation Home]../README.md** | โ–ถ๏ธ **Next: [Quick Start]QUICK_START.md**