Wirerust
A high-performance, modular filter engine for structured data written in Rust. Wirerust provides a clean, extensible implementation for parsing, compiling, and executing filter expressions against runtime data with strong type safety and excellent performance.
Features
β¨ Core Capabilities
- Schema-driven filtering: Define field types and constraints for your data
- Expression parsing: Parse human-readable filter expressions into an AST
- Compilation: Compile expressions to efficient closures for fast execution
- Type safety: Strong type checking with comprehensive error handling
- Extensible functions: Register built-in or custom filter functions
- Serialization: Full Serde support for schemas, contexts, and expressions
π§ Supported Types
- Primitives:
bool,int,bytes,string - Network:
ip(IPv4/IPv6 addresses) - Collections:
array,mapwith type inference - Special:
unknownfor dynamic typing
β‘ Performance
- Zero-copy parsing where possible
- Compiled expressions for optimal runtime performance
- Efficient memory usage with Arc-based sharing
- Property-based testing ensures correctness
Quick Start
Add to your Cargo.toml:
[]
= "0.1.0"
Basic usage:
use ;
// Create an engine with schema
let engine = new
.field
.field
.field
.build;
// Parse and compile a filter
let filter = engine.parse_and_compile.unwrap;
// Create context with data
let mut ctx = new;
ctx.set.unwrap;
ctx.set.unwrap;
// Execute the filter
assert!;
Advanced Usage
Custom Functions
use ;
;
let engine = new
.field
.register_function
.build;
Complex Expressions
// IP address filtering
let filter = engine.parse_and_compile.unwrap;
// String operations with functions
let filter = engine.parse_and_compile.unwrap;
// Logical combinations
let filter = engine.parse_and_compile.unwrap;
Built-in Functions
| Function | Description | Example |
|---|---|---|
len() |
Get length of string/array | len(name) > 5 |
starts_with() |
Check string prefix | starts_with(path, "/api/") |
ends_with() |
Check string suffix | ends_with(filename, ".json") |
sum() |
Sum array of numbers | sum(scores) > 100 |
upper() |
Convert to uppercase | upper(method) == "GET" |
Architecture
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Filter String βββββΆβ AST (FilterExpr)βββββΆβ CompiledFilter β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ
β Type Checker β β Execution β
βββββββββββββββββββ βββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ
β Schema β β Context β
βββββββββββββββββββ βββββββββββββββββββ
Core Components
- Schema: Field definitions and type constraints
- Parser: Converts filter strings to AST
- Compiler: Optimizes AST to executable closures
- Context: Runtime value storage with type checking
- Functions: Extensible function registry
- Types: Strong type system with inference
Performance
Wirerust is designed for high-performance scenarios:
- Zero-copy parsing where possible
- Compiled expressions avoid repeated parsing
- Efficient memory usage with smart pointer sharing
- Type-safe execution prevents runtime errors
- Property-based testing ensures correctness
Benchmarks show excellent performance for typical filter operations.
Development
Prerequisites
- Rust 1.88.0 or later
- Git
Setup
Running Tests
# Run all tests
# Run with all features
# Run benchmarks
# Run clippy
Version Management
# Bump patch version (0.1.0 -> 0.1.1)
# Bump minor version (0.1.0 -> 0.2.0)
# Bump major version (0.1.0 -> 1.0.0)
Roadmap
Current Status β
- Core filter engine with schema support
- Expression parsing and compilation
- Type-safe execution context
- Built-in function library
- Comprehensive test suite
- Property-based testing
- Serialization support
Planned Features π§
- Enhanced type inference for arrays and maps
- Dynamic operator registration for extensibility
- FFI/WASM bindings for cross-language use
- Advanced error handling with detailed diagnostics
- Performance benchmarks and optimization
- Query optimization for complex expressions
- Caching layer for compiled filters
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Development Guidelines
- Tests: Ensure all tests pass with
cargo test - Style: Follow Rust idioms and run
cargo clippy - Documentation: Add docs for new features
- Commits: Use conventional commit messages
Getting Started
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the full test suite
- Submit a pull request
License
This project is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Acknowledgments
- Inspired by Cloudflare's wirefilter
- Built with modern Rust idioms and best practices
- Community-driven development and feedback
Wirerust - Fast, safe, and extensible filtering for Rust applications.