[][src]Crate rustlogic

Hello fellow Rustacians! RustLogic is a crate for parsing and handling simple logical expressings.

This crate contains the basic foundation for handling stringed logical formulas. 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!

Example

4-1 Multiplexer

let multiplexer_4_to_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
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!

Enums

LogicNode

An Enum of all the possible states of a head of a logical formula

Constants

AND_SYMBOL

The symbol used for the AND operation

FALSE_SYMBOL

The symbol used for false state

GROUP_CLOSE_SYMBOL

The closing symbol of a priority group

GROUP_OPEN_SYMBOL

The opening symbol of a priority group

NOT_SYMBOL

The symbol used for the NOT operation

OR_SYMBOL

The symbol used for the OR operation

TRUE_SYMBOL

The symbol used for true state

VARIABLE_CLOSE_SYMBOL

The closing symbol for a variable

VARIABLE_OPEN_SYMBOL

The opening symbol for a variable

Functions

parse

Parse a formula string into in LogicNode object