[−][src]Function rustlogic::parse
pub fn parse(input_string: &str) -> Result<LogicNode, usize>
Parse a formula string into in LogicNode object
Outputs a results with an ok of the LogicNode or the location of the error
Examples
Basic usage (A pure variable)
let a_variable = parse("[a]").expect("Failed to parse variable"); let mut variable_map = HashMap::new(); variable_map.insert("a", true); let value = a_variable.get_value_from_variables(&variable_map).unwrap(); println!("{}", value); // Will print true!
4-1 Multiplexer
let multiplexer_4_to_1 = 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 variable_map.insert("a", true); variable_map.insert("b", false); variable_map.insert("c", false); variable_map.insert("d", true); // Selector: 11 variable_map.insert("x", true); variable_map.insert("y", true); // Should select fourth item from bus so true let value = multiplexer_4_to_1.get_value_from_variables(&variable_map).unwrap(); println!("{}", value); // Will print true!