Struct bet::BeTree[][src]

pub struct BeTree<Op, Atom> where
    Op: Debug + Clone + PartialEq,
    Atom: Debug + Clone
{ /* fields omitted */ }

An expression which may contain unary and binary operations

Implementations

impl<Op, Atom> BeTree<Op, Atom> where
    Op: Debug + Clone + PartialEq,
    Atom: Debug + Clone
[src]

pub fn new() -> Self[src]

create an empty expression, ready to be completed

pub fn is_empty(&self) -> bool[src]

tells whether the expression is devoid of any atom

pub fn is_atomic(&self) -> bool[src]

tell whether the tree is exactly one atom

pub fn atoms(self) -> Vec<Atom>[src]

take the atoms of the tree

pub fn iter_atoms<'a>(&'a self) -> Iter<'a, Atom>[src]

iterate on all atoms

pub fn current_atom<'a>(&'a self) -> Option<&'a Atom>[src]

returns a reference to the last atom if it’s the last pushed token. Return none in other cases (including when no atom has been pushed at all)

pub fn get_openess(&self) -> usize[src]

return the count of open parenthesis minus the one of closing parenthesis. Illegal closing parenthesis are ignored (hence why this count can be a usize)

pub fn push_atom(&mut self, atom: Atom)[src]

add an atom in a left-to-right expression building

pub fn mutate_or_create_atom<Create>(&mut self, create: Create) -> &mut Atom where
    Create: Fn() -> Atom, 
[src]

if the last change was an atom pushed or modified, return a mutable reference to this atom. If not, push a new atom and return a mutable reference to it.

pub fn open_par(&mut self)[src]

add an opening parenthesis to the expression

pub fn close_par(&mut self)[src]

add a closing parenthesis to the expression

pub fn push_operator(&mut self, operator: Op)[src]

add an operator right of the expression

The context will decide whether it’s unary or binary

pub fn accept_unary_operator(&self) -> bool[src]

tell whether it would make sense to push a unary operator at this point (for example it makes no sense just after an atom)

pub fn accept_binary_operator(&self) -> bool[src]

tell whether it would make sense to push a binary operator at this point (for example it makes no sense just after another operator)

pub fn accept_atom(&self) -> bool[src]

tell whether it would make sense to push an atom at this point (for example it makes no sense just after a closing parenthesis)

pub fn accept_opening_par(&self) -> bool[src]

tell whether it would make sense to open a parenthesis at this point (for example it makes no sense just after a closing parenthesis)

pub fn accept_closing_par(&self) -> bool[src]

tell whether it would make sense to close a parenthesis at this point (for example it makes no sense just after an operator or if there are more closing parenthesis than opening ones)

pub fn try_map_atoms<Atom2, Err, F>(
    &self,
    f: F
) -> Result<BeTree<Op, Atom2>, Err> where
    Atom2: Debug + Clone,
    F: Fn(&Atom) -> Result<Atom2, Err>, 
[src]

produce a new expression by applying a transformation on all atoms

The operation will stop at the first error

pub fn eval<R, EvalAtom, EvalOp, ShortCircuit>(
    &self,
    eval_atom: EvalAtom,
    eval_op: EvalOp,
    short_circuit: ShortCircuit
) -> Option<R> where
    EvalAtom: Fn(&Atom) -> R,
    EvalOp: Fn(&Op, R, Option<R>) -> R,
    ShortCircuit: Fn(&Op, &R) -> bool
[src]

evaluate the expression.

eval_atom will be called on all atoms (leafs) of the expression while eval_op will be used to join values until the final result is obtained.

short_circuit will be called on all binary operations with the operator and the left operands as arguments. If it returns true then the right operand isn’t evaluated (it’s guaranteed so it may serve as guard).

This function should be used when neither atom evaluation nor operator execution can raise errors (this usually means consistency checks have been done during parsing).

pub fn eval_faillible<Err, R, EvalAtom, EvalOp, ShortCircuit>(
    &self,
    eval_atom: EvalAtom,
    eval_op: EvalOp,
    short_circuit: ShortCircuit
) -> Result<Option<R>, Err> where
    EvalAtom: Fn(&Atom) -> Result<R, Err>,
    EvalOp: Fn(&Op, R, Option<R>) -> Result<R, Err>,
    ShortCircuit: Fn(&Op, &R) -> bool
[src]

evaluate the expression.

eval_atom will be called on all atoms (leafs) of the expression while eval_op will be used to join values until the final result is obtained.

short_circuit will be called on all binary operations with the operator and the left operands as arguments. If it returns true then the right operand isn’t evaluated (it’s guaranteed so it may serve as guard).

This function should be used when errors are expected during either atom evaluation or operator execution (for example because parsing was lax). The first Error returned by one of those functions breaks the evaluation and is returned.

Trait Implementations

impl<Op: Clone, Atom: Clone> Clone for BeTree<Op, Atom> where
    Op: Debug + Clone + PartialEq,
    Atom: Debug + Clone
[src]

impl<Op: Debug, Atom: Debug> Debug for BeTree<Op, Atom> where
    Op: Debug + Clone + PartialEq,
    Atom: Debug + Clone
[src]

impl<Op, Atom> Default for BeTree<Op, Atom> where
    Op: Debug + Clone + PartialEq,
    Atom: Debug + Clone
[src]

Auto Trait Implementations

impl<Op, Atom> RefUnwindSafe for BeTree<Op, Atom> where
    Atom: RefUnwindSafe,
    Op: RefUnwindSafe

impl<Op, Atom> Send for BeTree<Op, Atom> where
    Atom: Send,
    Op: Send

impl<Op, Atom> Sync for BeTree<Op, Atom> where
    Atom: Sync,
    Op: Sync

impl<Op, Atom> Unpin for BeTree<Op, Atom> where
    Atom: Unpin,
    Op: Unpin

impl<Op, Atom> UnwindSafe for BeTree<Op, Atom> where
    Atom: UnwindSafe,
    Op: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.