[][src]Trait egg::Language

pub trait Language: Debug + Clone + Eq + Ord + Hash {
    fn matches(&self, other: &Self) -> bool;
fn children(&self) -> &[Id];
fn children_mut(&mut self) -> &mut [Id]; fn for_each<F: FnMut(Id)>(&self, f: F) { ... }
fn for_each_mut<F: FnMut(&mut Id)>(&mut self, f: F) { ... }
fn display_op(&self) -> &dyn Display { ... }
fn from_op_str(op_str: &str, children: Vec<Id>) -> Result<Self, String> { ... }
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
, { ... } }

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.

Note that the default implementations of from_op_str and display_op panic. You should override them if you want to parse or pretty-print expressions. define_language! implements these for you.

See SymbolLang for quick-and-dirty use cases.

Required methods

fn matches(&self, other: &Self) -> bool

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

fn children(&self) -> &[Id]

Return a slice of the children Ids.

fn children_mut(&mut self) -> &mut [Id]

Return a mutable slice of the children Ids.

Loading content...

Provided methods

fn for_each<F: FnMut(Id)>(&self, f: F)

Runs a given function on each child Id.

fn for_each_mut<F: FnMut(&mut Id)>(&mut self, f: F)

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

fn display_op(&self) -> &dyn Display

Returns something that will print the operator.

Default implementation panics, so make sure to implement this if you want to print Language elements. The define_language! macro will implement this for you.

fn from_op_str(op_str: &str, children: Vec<Id>) -> Result<Self, String>

Given a string for the operator and the children, tries to make an enode.

Default implementation panics, so make sure to implement this if you want to parse Language elements. The define_language! macro will implement this for you.

fn len(&self) -> usize

Returns the number of the children this enode has.

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

fn is_leaf(&self) -> bool

Returns true if this enode has no children.

fn update_children<F: FnMut(Id) -> Id>(&mut self, f: F)

Runs a given function to replace the children.

fn map_children<F: FnMut(Id) -> Id>(self, f: F) -> Self

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

fn fold<F, T>(&self, init: T, f: F) -> T where
    F: FnMut(T, Id) -> T,
    T: Clone

Folds over the children, given an initial accumulator.

Loading content...

Implementors

impl Language for SymbolLang[src]

Loading content...