[−][src]Enum rustlogic::LogicNode
An Enum of all the possible states of a head of a logical formula
Variants
AND operation of left and right
OR operation of left and right
NOT operation of child
True, always returns true
False, always returns false
Variable(String)
Variable, always returns value of variable passed in
Methods
impl LogicNode
[src]
pub fn get_value_from_variables(
&self,
variables: &HashMap<&str, bool>
) -> Result<bool, String>
[src]
&self,
variables: &HashMap<&str, bool>
) -> Result<bool, String>
Will retrieve the value of a LogicNode given a HashMap of variables
Output
Will output a result type with either the value of the LogicNode given the Hashmap or will give a error with the variable missing from the 'variables' argument given.
Examples
X-OR
let xor = parse("([a]|[b])&~([a]&[b])") .expect("Failed to parse xor gate"); let mut variable_map = HashMap::new(); variable_map.insert("a", true); variable_map.insert("b", true); let value_1 = xor.get_value_from_variables(&variable_map).unwrap(); println!("First value: {}!", value_1); // Will print false! variable_map.insert("a", false); let value_2 = xor.get_value_from_variables(&variable_map).unwrap(); println!("Second value: {}!", value_1); // Will print true! variable_map.insert("b", false); let value_3 = xor.get_value_from_variables(&variable_map).unwrap(); println!("Third value: {}!", value_1); // Will print false!
pub fn get_value(&self) -> Result<bool, String>
[src]
Will retrieve the value of a LogicNode given purely the formula
Output
Will return a result with either the value of the LogicNode or an error value containing the name of the (or one of the) variable contained within the LogicNode.
Examples
Basic usage
let and_of_true_and_false = parse("0&1") .expect("Unable to parse AND of true and false"); let or_of_true_and_false = parse("0|1") .expect("Unable to parse OR of true and false"); let value_1 = and_of_true_and_false.get_value().unwrap(); println!("0&1: {}", value_1); // Will return false! let value_2 = or_of_true_and_false.get_value().unwrap(); println!("0|1: {}", value_2); // Will return true!
pub fn contains_variable(&self) -> bool
[src]
Will return whether a given LogicNode contains a variable
Examples
Basic usage
let with_variable = parse("([a]&0)") .expect("Unable to parse with variable"); let without_variable = parse("(1&0)") .expect("Unable to parse without variable"); // Will return true! println!("First contains variable: {}", with_variable.contains_variable()); // Will return false! println!("Second contains variable: {}", without_variable.contains_variable());
pub fn get_variables(&self) -> Vec<String>
[src]
Returns a sorted vector of all Variables used in a LogicNode
Examples
NOR
let nor = parse("~([a]|[b])") .expect("Unable to parse with variable"); // Will return ["a", "b"] println!("Variables in nor: {:?}", nor.get_variables());
pub fn insert_formula(&self, variable: &str, formula: &LogicNode) -> LogicNode
[src]
Inserts formula in place of variable
Examples
Insert AND in OR
let or = parse("[AND]|[b]").expect("Error parsing or"); let and_in_or = or.insert_formula( "AND", &parse("[x]&[y]").expect("Error parsing AND") ); println!("{}", and_in_or); // Will print (([x]&[y])|[b])
Trait Implementations
impl Clone for LogicNode
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for LogicNode
[src]
impl Display for LogicNode
[src]
Auto Trait Implementations
impl RefUnwindSafe for LogicNode
impl Send for LogicNode
impl Sync for LogicNode
impl Unpin for LogicNode
impl UnwindSafe for LogicNode
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,