Instead of manually writing transition loops, Banish evaluates rules within a state until no rule fires (a fixed-point model), then transitions. The macro expands into regular Rust, which allows for seamless integration.
The goal is to make complex rule logic and state machines easier to express while keeping runtime costs identical to handwritten code.
The project was featured as Crate of the Week in the Rust newsletter this week. I'd love to hear your feedback.
Example: use banish::banish;
fn main() { let buffer = ["No".to_string(), "hey".to_string()]; let target = "hey".to_string(); let idx = find_index(&buffer, &target); print!("{:?}", idx) }
fn find_index(buffer: &[String], target: &str) -> Option<usize> { let mut idx = 0; banish! { @search // This must be first to prevent out-of-bounds panic below. not_found ? idx >= buffer.len() { return None; }
found ? buffer[idx] != target {
idx += 1;
} !? { return Some(idx); }
// Rule triggered so we re-evalutate rules in search.
}
}