ELO Rust Code Generation Target
A production-grade Rust code generation target for the ELO validation language. Converts ELO validation expressions into zero-cost Rust validators with <1ยตs execution time.
Features
โจ High Performance
- Generated validators execute in <1ยตs
- Zero-copy design with minimal allocations
- Compile-time optimization via Rust compiler
๐ฏ Comprehensive Validation
- String operations: regex matching, contains, length, case conversion, trim, starts_with, ends_with
- Date/time functions: today(), now(), age(), days_since(), date parsing
- Array operations: contains, any, all, length, is_empty
- Type checking: is_null, is_some for Option types
๐ ๏ธ Developer Friendly
- Simple validator macro:
#[elo_validator(elo = "expression")] - CLI tool for code generation:
elo compile --expression "age >= 18" - Framework integration examples (Actix-web, Axum)
- Comprehensive error reporting
Quick Start
As a Library
use RustCodeGenerator;
let gen = new;
let code = gen.generate_function_signature?;
Using the CLI
# Generate validator from command line
# Read from file, write to file
# Validate ELO expression syntax
In Actix-web
use ;
use ValidationErrors;
;
async
Supported Functions
String Functions (8 total)
matches(pattern)- Regex pattern matchingcontains(substring)- Substring searchlength()- String lengthuppercase()- Convert to uppercaselowercase()- Convert to lowercasetrim()- Remove whitespacestarts_with(prefix)- Prefix checkends_with(suffix)- Suffix check
DateTime Functions (5 total)
today()- Current datenow()- Current UTC timestampage(birthdate)- Age calculation from birthdatedays_since(date)- Days elapseddate("YYYY-MM-DD")- Parse ISO 8601 date
Array Functions (5 total)
contains(value)- Element searchany(predicate)- Existence check with closureall(predicate)- Universal check with closurelength()- Array sizeis_empty()- Empty check
Type Functions (2 total)
is_null()- Option null checkis_some()- Option some check
Examples
Age Validation
age >= 18
Email Validation
email matches "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
Complex User Validation
email matches pattern &&
username.length() >= 3 && username.length() <= 20 &&
age >= 18 &&
age <= 120 &&
verified == true &&
!banned
Permission Checking
(roles.contains("admin") || roles.contains("moderator")) &&
verified == true &&
!banned
Order Validation
items.length() > 0 &&
items.all(quantity > 0 && price > 0) &&
total > 0 &&
days_since(created_at) < 30
API Documentation
RustCodeGenerator
Main code generator for transforming ELO expressions to Rust code.
OperatorGenerator
Generates code for binary and unary operations.
;
FunctionGenerator
Generates code for standard library functions.
;
Project Statistics
- Total Tests: 573 (100% passing) - +150 tests for security coverage
- Code Coverage: 65%+ of codebase
- Security Tests: 37 dedicated security tests
- Standard Library Functions: 20+ implemented
- Framework Examples: Actix-web, Axum
- Code Generation: Full AST visitor pattern
- Performance: <1ยตs validator execution
- Security: Enterprise-grade hardening (7 vulnerabilities identified & fixed)
Testing
Run the full test suite:
Run specific test category:
Run examples:
Building
# Debug build
# Release build with optimizations
# CLI tool
# Documentation
Architecture
src/
โโโ lib.rs # Public API
โโโ codegen/
โ โโโ mod.rs # Main RustCodeGenerator
โ โโโ operators.rs # Binary/unary operators
โ โโโ functions.rs # String/date/array functions
โ โโโ types.rs # Type system
โ โโโ errors.rs # Error handling
โโโ runtime/
โ โโโ mod.rs # ValidationError types
โโโ bin/
โโโ elo.rs # CLI tool
tests/
โโโ string_functions.rs # 34 tests
โโโ datetime_functions.rs # 39 tests
โโโ array_functions.rs # 37 tests
โโโ macro_usage.rs # 38 tests
โโโ ...
examples/
โโโ simple_validator.rs # Basic example
โโโ actix_validator.rs # Actix integration
โโโ axum_validator.rs # Axum integration
Performance
Generated validators are designed for minimal overhead:
- Code Generation: <100ms per expression
- Validator Execution: <1ยตs per check
- Memory Overhead: Minimal allocations
- Binary Size: ~50 lines typical validator code
License
MIT
Contributing
Contributions are welcome! Please ensure:
- All tests pass:
cargo test - Code passes clippy:
cargo clippy --all-targets -- -D warnings - Code is formatted:
cargo fmt
Support
For issues, questions, or contributions, please visit: https://github.com/enspirit/elo
Version: 0.1.1 Status: โ Production Ready Last Updated: February 8, 2026 Security: โ Fully Audited (7 vulnerabilities fixed) Tests: โ 573 passing (100%) Coverage: โ 65%+