Trait egg::Language[][src]

pub trait Language: Debug + Clone + Eq + Ord + Hash {
Show 14 methods fn matches(&self, other: &Self) -> bool;
fn children(&self) -> &[Id]
Notable traits for &'_ mut [u8]
impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
;
fn children_mut(&mut self) -> &mut [Id]
Notable traits for &'_ mut [u8]
impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
; fn for_each<F: FnMut(Id)>(&self, f: F) { ... }
fn for_each_mut<F: FnMut(&mut Id)>(&mut self, f: F) { ... }
fn try_for_each<E, F>(&self, f: F) -> Result<(), E>
    where
        F: FnMut(Id) -> Result<(), E>,
        E: Clone
, { ... }
fn len(&self) -> usize { ... }
fn is_leaf(&self) -> bool { ... }
fn update_children<F: FnMut(Id) -> Id>(&mut self, f: F) { ... }
fn map_children<F: FnMut(Id) -> Id>(self, f: F) -> Self { ... }
fn fold<F, T>(&self, init: T, f: F) -> T
    where
        F: FnMut(T, Id) -> T,
        T: Clone
, { ... }
fn all<F: FnMut(Id) -> bool>(&self, f: F) -> bool { ... }
fn any<F: FnMut(Id) -> bool>(&self, f: F) -> bool { ... }
fn to_recexpr<'a, F>(&self, child_recexpr: F) -> RecExpr<Self>
    where
        Self: 'a,
        F: FnMut(Id) -> &'a [Self]
, { ... }
}
Expand description

Trait that defines a Language whose terms will be in the EGraph.

Check out the define_language! macro for an easy way to create a Language.

If you want to pretty-print expressions, you should implement Display to display the language node’s operator. For example, a language node Add([Id; 2]) might be displayed as “+”.

To parse expressions from strings you should also implement FromOp.

The define_language! macro automatically implements both Display and FromOp.

See SymbolLang for quick-and-dirty use cases.

Required methods

Returns true if this enode matches another enode. This should only consider the operator, not the children Ids.

Returns the children of this e-node.

Returns a mutable slice of the children of this e-node.

Provided methods

Runs a given function on each child Id.

Runs a given function on each child Id, allowing mutation of that Id.

Runs a falliable function on each child, stopping if the function returns an error.

Returns the number of the children this enode has.

The default implementation uses fold to accumulate the number of children.

Returns true if this enode has no children.

Runs a given function to replace the children.

Creates a new enode with children determined by the given function.

Folds over the children, given an initial accumulator.

Returns true if the predicate is true on all children. Does not short circuit.

Returns true if the predicate is true on any children. Does not short circuit.

Make a RecExpr converting this enodes children to RecExprs

Example
let a_plus_2: RecExpr<SymbolLang> = "(+ a 2)".parse().unwrap();
// here's an enode with some meaningless child ids
let enode = SymbolLang::new("*", vec![Id::from(0), Id::from(0)]);
// make a new recexpr, replacing enode's children with a_plus_2
let recexpr = enode.to_recexpr(|_id| a_plus_2.as_ref());
assert_eq!(recexpr, "(* (+ a 2) (+ a 2))".parse().unwrap())

Implementors