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

An expression which may contain unary and binary operations

Implementations

create an empty expression, ready to be completed

tells whether the expression is devoid of any atom

tell whether the tree is exactly one atom

take the atoms of the tree

iterate on all atoms

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)

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)

add one of the possible token: parenthesis, operator or atom

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

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.

add an opening parenthesis to the expression

add a closing parenthesis to the expression

add an operator right of the expression

The context will decide whether it’s unary or binary

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

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

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

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

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)

produce a new expression by applying a transformation on all atoms

The operation will stop at the first error

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).

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

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.