[][src]Struct egg::ENode

pub struct ENode<O, Child = Id> {
    pub op: O,
    pub children: SmallVec<[Child; 2]>,
}

An operator from the user-defined Language with some children.

An ENode is operator from the user-provided Language with zero or more children. Note that ENode is generic over both the Language and the type of the children. In the typical setting (inside and EClass), the children of an ENode are elcass Ids, so the second generic parameter defaults to Id. In other cases (cost functions or metadata), the generic parameter may be something else.

Fields

op: O

The operator from the user-defined Language

children: SmallVec<[Child; 2]>

The children of the ENode. In most cases, the child type is Id.

Methods

impl<L: Language, Child> ENode<L, Child>[src]

pub fn leaf(op: L) -> Self[src]

Create a new ENode with no children. Equivalent to calling ENode::new with no children.

pub fn new<I>(op: L, children: I) -> Self where
    I: IntoIterator<Item = Child>, 
[src]

Create a new ENode.

pub fn try_new<Error, I>(op: L, children: I) -> Result<Self, Error> where
    I: IntoIterator<Item = Result<Child, Error>>, 
[src]

Try to create an ENode with a falliable child iterator.

Example

define_language! {
    enum Math {
        Num(i32),
        Add = "+",
        Mul = "*",
    }
}

// This is obviously silly, but maybe you have some more
// complex function
fn non_neg(i: i32) -> Result<u32, String> {
    if i >= 0 {
        Ok(i as u32)
    } else {
        Err(format!("{} is less than 0", i))
    }
}
let r1: Result<ENode<Math, u32>, String> = ENode::try_new(
    Math::Add,
    vec![non_neg(1), non_neg(8)]
);
let r2: Result<ENode<Math, u32>, String> = ENode::try_new(
    Math::Add,
    vec![non_neg(-1), non_neg(8)]
);
assert_eq!(r1, Ok(enode!(Math::Add, 1, 8)));
assert_eq!(r2, Err("-1 is less than 0".into()));

pub fn map_children<Child2, F>(&self, f: F) -> ENode<L, Child2> where
    Child: Clone,
    F: FnMut(Child) -> Child2, 
[src]

Create a new ENode by mapping a function over the children.

enode.map_children(f) is equivalent to:

ENode::new(
    enode.op.clone(),
    enode.children.iter().cloned().map(f),
)

pub fn map_children_result<Child2, F, Error>(
    &self,
    f: F
) -> Result<ENode<L, Child2>, Error> where
    Child: Clone,
    F: FnMut(Child) -> Result<Child2, Error>, 
[src]

Create a new ENode by mapping a falliable function over the children.

enode.map_children_result(f) is equivalent to:

ENode::try_new(
    enode.op.clone(),
    enode.children.iter().cloned().map(f),
)

Trait Implementations

impl<L> AsRef<ENode<L, RecExpr<L>>> for RecExpr<L>[src]

impl<L> Borrow<ENode<L, RecExpr<L>>> for RecExpr<L>[src]

impl<O: Clone, Child: Clone> Clone for ENode<O, Child>[src]

impl<O: Debug, Child: Debug> Debug for ENode<O, Child>[src]

impl<O: Eq, Child: Eq> Eq for ENode<O, Child>[src]

impl<L> From<ENode<L, RecExpr<L>>> for RecExpr<L>[src]

impl<O: Hash, Child: Hash> Hash for ENode<O, Child>[src]

impl<O: PartialEq, Child: PartialEq> PartialEq<ENode<O, Child>> for ENode<O, Child>[src]

impl<O, Child> StructuralEq for ENode<O, Child>[src]

impl<O, Child> StructuralPartialEq for ENode<O, Child>[src]

Auto Trait Implementations

impl<O, Child> RefUnwindSafe for ENode<O, Child> where
    Child: RefUnwindSafe,
    O: RefUnwindSafe

impl<O, Child> Send for ENode<O, Child> where
    Child: Send,
    O: Send

impl<O, Child> Sync for ENode<O, Child> where
    Child: Sync,
    O: Sync

impl<O, Child> Unpin for ENode<O, Child> where
    Child: Unpin,
    O: Unpin

impl<O, Child> UnwindSafe for ENode<O, Child> where
    Child: RefUnwindSafe + UnwindSafe,
    O: 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<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?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.