pub enum NodeInner {
Const(Const),
Unary(Unary),
Binary(Binary),
Var(Var),
Piecewise(Piecewise),
}Expand description
Concrete varieties of a node which together compose an AST.
Variants§
Const(Const)
Some constant value, like a coefficient or offset.
Unary(Unary)
An operation which takes a single operand.
Binary(Binary)
An operation which takes two operands.
Var(Var)
Some unknown value.
Piecewise(Piecewise)
A piecewise function.
Implementations§
Source§impl NodeInner
impl NodeInner
Sourcepub fn new_const<V: Into<TyValue>>(v: V) -> Self
pub fn new_const<V: Into<TyValue>>(v: V) -> Self
Creates a new constant node with the given value.
Sourcepub fn new_var<S: Into<String>>(ident: S) -> Self
pub fn new_var<S: Into<String>>(ident: S) -> Self
Creates a new variable node with the given identifier.
Sourcepub fn as_const(&self) -> Option<&Const>
pub fn as_const(&self) -> Option<&Const>
Returns a ref to the inner Const if this node is that variant.
Sourcepub fn as_unary(&self) -> Option<&Unary>
pub fn as_unary(&self) -> Option<&Unary>
Returns a ref to the inner Unary if this node is that variant.
Sourcepub fn as_binary(&self) -> Option<&Binary>
pub fn as_binary(&self) -> Option<&Binary>
Returns a ref to the inner Binary if this node is that variant.
Sourcepub fn as_var(&self) -> Option<&Var>
pub fn as_var(&self) -> Option<&Var>
Returns a ref to the inner Var if this node is that variant.
Sourcepub fn pretty_str(&self, parent_precedence: Option<usize>) -> String
pub fn pretty_str(&self, parent_precedence: Option<usize>) -> String
Returns a neatly-formatted string representation of the AST.
Trait Implementations§
Source§impl AstNode for NodeInner
impl AstNode for NodeInner
Source§fn descendant_types(&self) -> impl Iterator<Item = Option<Ty>>
fn descendant_types(&self) -> impl Iterator<Item = Option<Ty>>
Returns the types of the operands of this node.
Source§fn finite_eval<C: EvalContext>(&self, ctx: &C) -> Result<TyValue, EvalError>
fn finite_eval<C: EvalContext>(&self, ctx: &C) -> Result<TyValue, EvalError>
Attempts to evaluate the AST to a single finite value.
Source§fn eval<C: EvalContext>(
&self,
ctx: &C,
) -> Result<Box<dyn Iterator<Item = Result<TyValue, EvalError>> + '_>, EvalError>
fn eval<C: EvalContext>( &self, ctx: &C, ) -> Result<Box<dyn Iterator<Item = Result<TyValue, EvalError>> + '_>, EvalError>
Evaluates all possible values of the AST.
Source§fn eval_interval<C: EvalContextInterval>(
&self,
ctx: &C,
) -> Result<Box<dyn Iterator<Item = Result<(TyValue, TyValue), EvalError>> + '_>, EvalError>
fn eval_interval<C: EvalContextInterval>( &self, ctx: &C, ) -> Result<Box<dyn Iterator<Item = Result<(TyValue, TyValue), EvalError>> + '_>, EvalError>
Interval variant of AstNode::eval.
Source§fn walk(&self, depth_first: bool, cb: &mut impl FnMut(&NodeInner) -> bool)
fn walk(&self, depth_first: bool, cb: &mut impl FnMut(&NodeInner) -> bool)
Recursively executes the given function on every node in the AST.
The walk will end early if the given function returns false and
the invocation was not depth first.
Source§fn walk_mut(
&mut self,
depth_first: bool,
cb: &mut impl FnMut(&mut NodeInner) -> bool,
)
fn walk_mut( &mut self, depth_first: bool, cb: &mut impl FnMut(&mut NodeInner) -> bool, )
Recursively executes the given function on every node in the AST.
The walk will end early if the given function returns false and
the invocation was not depth first.
Source§fn iter_children(&self) -> impl Iterator<Item = &NodeInner>
fn iter_children(&self) -> impl Iterator<Item = &NodeInner>
Iterates through the child nodes of this node.
Source§fn get<I: Iterator<Item = usize>>(&self, i: I) -> Option<&NodeInner>
fn get<I: Iterator<Item = usize>>(&self, i: I) -> Option<&NodeInner>
Returns the nested child described by the given sequence. Read more
impl Eq for NodeInner
impl StructuralPartialEq for NodeInner
Auto Trait Implementations§
impl Freeze for NodeInner
impl RefUnwindSafe for NodeInner
impl Send for NodeInner
impl Sync for NodeInner
impl Unpin for NodeInner
impl UnwindSafe for NodeInner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more