[−][src]Struct bet::BeTree
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]
Op: Debug + Clone + PartialEq,
Atom: Debug + Clone,
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 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]
Create: Fn() -> Atom,
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]
&self,
f: F
) -> Result<BeTree<Op, Atom2>, Err> where
Atom2: Debug + Clone,
F: Fn(&Atom) -> Result<Atom2, Err>,
produce a new expression by applying a transformation on all atoms
The operation will stop at the first error
pub fn eval<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]
&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,
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).
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]
Op: Debug + Clone + PartialEq,
Atom: Debug + Clone,
impl<Op: Debug, Atom: Debug> Debug for BeTree<Op, Atom> where
Op: Debug + Clone + PartialEq,
Atom: Debug + Clone,
[src]
Op: Debug + Clone + PartialEq,
Atom: Debug + Clone,
impl<Op, Atom> Default for BeTree<Op, Atom> where
Op: Debug + Clone + PartialEq,
Atom: Debug + Clone,
[src]
Op: Debug + Clone + PartialEq,
Atom: Debug + Clone,
Auto Trait Implementations
impl<Op, Atom> RefUnwindSafe for BeTree<Op, Atom> where
Atom: RefUnwindSafe,
Op: RefUnwindSafe,
Atom: RefUnwindSafe,
Op: RefUnwindSafe,
impl<Op, Atom> Send for BeTree<Op, Atom> where
Atom: Send,
Op: Send,
Atom: Send,
Op: Send,
impl<Op, Atom> Sync for BeTree<Op, Atom> where
Atom: Sync,
Op: Sync,
Atom: Sync,
Op: Sync,
impl<Op, Atom> Unpin for BeTree<Op, Atom> where
Atom: Unpin,
Op: Unpin,
Atom: Unpin,
Op: Unpin,
impl<Op, Atom> UnwindSafe for BeTree<Op, Atom> where
Atom: UnwindSafe,
Op: UnwindSafe,
Atom: UnwindSafe,
Op: UnwindSafe,
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, 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>,