[−][src]Struct egg::ENode
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 Id
s, 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]>
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]
I: IntoIterator<Item = Child>,
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]
I: IntoIterator<Item = Result<Child, Error>>,
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]
Child: Clone,
F: FnMut(Child) -> Child2,
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]
&self,
f: F
) -> Result<ENode<L, Child2>, Error> where
Child: Clone,
F: FnMut(Child) -> Result<Child2, Error>,
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]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<O: PartialEq, Child: PartialEq> PartialEq<ENode<O, Child>> for ENode<O, Child>
[src]
fn eq(&self, other: &ENode<O, Child>) -> bool
[src]
fn ne(&self, other: &ENode<O, Child>) -> bool
[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,
Child: RefUnwindSafe,
O: RefUnwindSafe,
impl<O, Child> Send for ENode<O, Child> where
Child: Send,
O: Send,
Child: Send,
O: Send,
impl<O, Child> Sync for ENode<O, Child> where
Child: Sync,
O: Sync,
Child: Sync,
O: Sync,
impl<O, Child> Unpin for ENode<O, Child> where
Child: Unpin,
O: Unpin,
Child: Unpin,
O: Unpin,
impl<O, Child> UnwindSafe for ENode<O, Child> where
Child: RefUnwindSafe + UnwindSafe,
O: UnwindSafe,
Child: RefUnwindSafe + UnwindSafe,
O: 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<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
fn equivalent(&self, key: &K) -> bool
[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>,