[][src]Trait automafish::Criteria

pub trait Criteria: Clone + PartialEq + Eq + Hash {
    type Input;
    pub fn is_match(&self, input: &Self::Input) -> bool;
pub fn is_empty(&self) -> bool;
pub fn and(&self, other: &Self) -> Self;
pub fn not(&self, other: &Self) -> Self;
pub fn any() -> Self; pub fn evaluation_order(&self) -> usize { ... } }

A trait defining transition criteria.

The criteria defines a condition that the StateMachine input needs to match for a specific state transition to occur. The input type of the state machine is indirectly defined by the Self::Input of the state machine criteria.

Associated Types

type Input

Input type for the state machien criteria.

Loading content...

Required methods

pub fn is_match(&self, input: &Self::Input) -> bool

Checks whether a given input is a match for a specific criteria.

pub fn is_empty(&self) -> bool

Checks if the Criteria represents an empty criteria that doesn't match any input.

Recognizing empty Criteria allows the Builder to simplify the final StateMachine. Returning false in case the Criteria is empty does not break the actual state processing, but will result in extra states and state transitions being included in the final StateMachine.

pub fn and(&self, other: &Self) -> Self

Combines two Criteria together.

The Builder will use this method when calculating state transitions in the final StateMachine between deterministic states representing several nondeterministic states defined in the Builder.

The Builder will only invoke this method with other being a criteria defined in the original state transitions by hand. An output of and or not is never used as the other parameter.

Example

#[derive(Clone, PartialEq, Eq, Hash)]
struct OneOf(BTreeSet<u32>);
impl Criteria for OneOf {
    fn and(&self, other: &Self) -> Self {
        OneOf(self.0.intersection(&other.0).copied().collect())
    }

// ... rest of the required methods.
}

let small = OneOf(vec![ 1, 2, 3, 4 ].into_iter().collect());
let even = OneOf(vec![ 2, 4, 6, 8 ].into_iter().collect());

let small_and_even = small.and(&even);

let input = 4;
assert_eq!(
    small.is_match(&input) && even.is_match(&input),
    small_and_even.is_match(&input));

pub fn not(&self, other: &Self) -> Self

Calculates a difference criteria that matches self but not other.

The Builder will use this method when calculating state transitions in the final StateMachine between deterministic states representing several nondeterministic states defined in the Builder.

The Builder will only invoke this method with other being a criteria defined in the original state transitions by hand. An output of and or not is never used as the other parameter.

This allows for some simplification in the resulting state. The Builder asking for criteria such as a.not(b) occurs in a situation where there is criteria b in some state transition that should take priority over the one for which the a.not(b) criteria applies. This means that as long as a.not(b) criteria has a lower evaluation order, it's perfectly valid to return a as a result of that not operation. An example of this would be the Self::any state, which can be returned as is, as long as it has the lowest evaluation order.

pub fn any() -> Self

A default criteria that matches everything.

In general this criteria shouldn't be used for is_match unless it appears explicitly in the user-specified Transition definitions. Instead the any-state is used as a building block when the Builder constructs the final transitions for the resulting deterministic finite automaton. The final states are any() combined with one or more and(..) and zero or more not(..).

Loading content...

Provided methods

pub fn evaluation_order(&self) -> usize

The evaluation order of the Criteria defines the order in which the state transitiosn are evaluated. Criteria with smaller evaluation order is processed first.

This allows some leeway in how accurate the Self::and and Self::not implementations are. See Self::not for more details.

Loading content...

Implementors

impl<T: Clone + Copy + PartialEq + Eq + Hash> Criteria for Condition<T>[src]

type Input = T

Loading content...