Hello fellow Rustacians! RustLogic is a crate for parsing and handling simple logical expressings.
This crate provides a fast way of parsing logical strings into a tree object. Furthermore, one can insert variables into this equation for single parsing-multiple outputs.
``` use std::collections::HashMap; let multiplexer4to_1 = rustlogic::parse( "([a]&~[x]&~[y])|([b]&~[x]&[y])|([c]&[x]&~[y])|([d]&[x]&[y])" ) .expect("Failed to parse 4-1 multiplexer");
let mut variable_map = HashMap::new();
// Input: 1001 variablemap.insert("a", true); variablemap.insert("b", false); variablemap.insert("c", false); variablemap.insert("d", true);
// Selector: 11 variablemap.insert("x", true); variablemap.insert("y", true);
// Should select fourth item from bus so true let value = multiplexer4to1.getvaluefromvariables(&variable_map).unwrap(); println!("{}", value); // Will print true! ```
``` use rustlogic::operators; use std::collections::HashMap;
// Define the set let operatorset = operators::commonsets::worded();
let parsed = rustlogic::customparse("(NOT $[A] AND TRUE) OR $[B]", &operatorset);
// We assign the variables to their values let mut hm = HashMap::new(); hm.insert("A", false); hm.insert("B", false);
// Now contains the value of the logical expression let value = parsed.unwrap().getvaluefrom_variables(&hm).unwrap(); ```
If you want to want to submit an issue or a pull request, please visit the GitHub page.
Thanks for your time and enjoy this crate!