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
Using the Validator Macro
use elo_validator;
;
let user = User ;
match validate
Using the CLI
# Parse and validate ELO expression
# Parse from file
# Compile with output
As a Library
use Parser;
use RustCodeGenerator;
// Parse ELO expression
let parser = new;
let ast = parser.parse?;
// Generate Rust code
let gen = new;
let code = gen.generate_validator?;
In Actix-web (With ELO Validator)
use ;
use elo_validator;
use ;
;
async
Supported Functions & Operators
String Functions (8)
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)
today()- Current datenow()- Current UTC timestampage(birthdate)- Age calculation from birthdatedays_since(date)- Days elapseddate("YYYY-MM-DD")- Parse ISO 8601 date
Temporal Keywords (16)
NOW, TODAY, TOMORROW, YESTERDAY, EPOCH,
UTC, START_OF_DAY, END_OF_DAY, START_OF_WEEK,
END_OF_WEEK, START_OF_MONTH, END_OF_MONTH,
START_OF_YEAR, END_OF_YEAR, MIDNIGHT, NOON
Array Functions (5)
contains(value)- Element searchany(predicate)- Existence check with closureall(predicate)- Universal check with closurelength()- Array sizeis_empty()- Empty check
Type Functions (2)
is_null()- Option null checkis_some()- Option some check
Operators
Arithmetic: +, -, *, /, %
Comparison: ==, !=, <, <=, >, >=
Logical: &&, ||, !
Expression Examples
Simple Validation
age >= 18
Email & Username Validation
email matches "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$" &&
username |> length() >= 3 && username |> length() <= 20
Temporal Validation (New in 0.4.0)
created_at >= TODAY &&
expires_at > NOW &&
updated_at < END_OF_DAY
Conditional Validation with Let Bindings
let username_len = username |> length() in
let email_valid = email matches "^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,}$" in
username_len >= 3 && username_len <= 20 && email_valid
User Account Validation with Guard
guard age >= 18 && verified in
email matches "^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,}$" &&
username |> length() >= 3
Permission Checking
(roles |> contains("admin") || roles |> contains("moderator")) &&
verified == true &&
active == true
Order Validation with Aggregation
items |> length() > 0 &&
items |> all(quantity > 0 && price > 0) &&
total > 0
Conditional Pricing with If Expression
if verified then price * 0.9 else price
Complex Policy Logic
let is_admin = roles |> contains("admin") in
let account_age = days_since(created_at) in
if is_admin then
account_age > 0
else
account_age > 30 && verified && payment_verified
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: 786 (100% passing)
- Code Coverage: 70%+ of codebase
- Production Code: 4,600+ lines
- Standard Library Functions: 20+ implemented
- Temporal Functions: 16 keywords supported
- Code Generation: Full AST visitor pattern with optimization
- Performance: <5ยตs full compilation, <1ยตs execution
- Security: Enterprise-grade hardening with comprehensive validation
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
โโโ parser/
โ โโโ mod.rs # Recursive descent parser
โ โโโ lexer.rs # Tokenization
โ โโโ error.rs # Parse errors with source context
โโโ ast/
โ โโโ mod.rs # AST definitions
โ โโโ visitor.rs # Visitor pattern for traversal
โโโ codegen/
โ โโโ mod.rs # Main RustCodeGenerator
โ โโโ ast_to_code.rs # AST visitor to TokenStream
โ โโโ operators.rs # Binary/unary operators
โ โโโ functions.rs # String/date/array functions
โ โโโ temporal.rs # Temporal type operations
โ โโโ type_inference.rs # Type inference engine
โ โโโ optimization.rs # Constant folding optimizer
โ โโโ types.rs # Type system & context
โ โโโ errors.rs # Code generation errors
โโโ runtime/
โ โโโ mod.rs # ValidationError types
โ โโโ value.rs # EloValue enum for runtime types
โ โโโ temporal.rs # Temporal value operations
โโโ security.rs # Input validation & security
โโโ bin/
โโโ elo.rs # CLI tool
tests/
โโโ error_handling.rs # 26 error tests
โโโ temporal_integration.rs # 14 temporal tests
โโโ parsing.rs # 9 benchmark tests
โโโ ... (19 other test modules, 700+ tests total)
benches/
โโโ parsing.rs # Performance benchmarks
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.4.1 Status: โ Production Ready Last Updated: February 8, 2026 Architecture: โ Complete (8 phases) Tests: โ 786 passing (100%) Coverage: โ 70%+ Benchmarks: โ <5ยตs compilation, <1ยตs execution