Enum NodeInner

Source
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

Source

pub fn new_const<V>(v: V) -> NodeInner
where V: Into<TyValue>,

Creates a new constant node with the given value.

Source

pub fn new_var<S>(ident: S) -> NodeInner
where S: Into<String>,

Creates a new variable node with the given identifier.

Source

pub fn as_const(&self) -> Option<&Const>

Returns a ref to the inner Const if this node is that variant.

Source

pub fn as_unary(&self) -> Option<&Unary>

Returns a ref to the inner Unary if this node is that variant.

Source

pub fn as_binary(&self) -> Option<&Binary>

Returns a ref to the inner Binary if this node is that variant.

Source

pub fn as_var(&self) -> Option<&Var>

Returns a ref to the inner Var if this node is that variant.

Source

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

Source§

fn returns(&self) -> Option<Ty>

Returns the type of the value this node yields.
Source§

fn descendant_types(&self) -> impl Iterator<Item = Option<Ty>>

Returns the types of the operands of this node.
Source§

fn finite_eval<C>(&self, ctx: &C) -> Result<TyValue, EvalError>
where C: EvalContext,

Attempts to evaluate the AST to a single finite value.
Source§

fn eval<C>( &self, ctx: &C, ) -> Result<Box<dyn Iterator<Item = Result<TyValue, EvalError>> + '_>, EvalError>
where C: EvalContext,

Evaluates all possible values of the AST.
Source§

fn eval_interval<C>( &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)

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, )

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 as_inner(&self) -> &NodeInner

Returns the concrete variant this AST node represents.
Source§

fn iter_children(&self) -> impl Iterator<Item = &NodeInner>

Iterates through the child nodes of this node.
Source§

fn get<I>(&self, i: I) -> Option<&NodeInner>
where I: Iterator<Item = usize>,

Returns the nested child described by the given sequence. Read more
Source§

fn get_mut<I>(&mut self, i: I) -> Option<&mut NodeInner>
where I: Iterator<Item = usize>,

Returns the mutable NodeInner described by the given path sequence. Read more
Source§

fn parsing_precedence(&self) -> Option<(bool, usize)>

Returns whether the operator is left-associative, and its precedence. Read more
Source§

impl Clone for NodeInner

Source§

fn clone(&self) -> NodeInner

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NodeInner

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for NodeInner

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<Binary> for NodeInner

Source§

fn from(n: Binary) -> NodeInner

Converts to this type from the input type.
Source§

impl From<Const> for NodeInner

Source§

fn from(n: Const) -> NodeInner

Converts to this type from the input type.
Source§

impl From<Node> for NodeInner

Source§

fn from(n: Node) -> NodeInner

Converts to this type from the input type.
Source§

impl From<NodeInner> for Node

Source§

fn from(n: NodeInner) -> Node

Converts to this type from the input type.
Source§

impl From<Piecewise> for NodeInner

Source§

fn from(p: Piecewise) -> NodeInner

Converts to this type from the input type.
Source§

impl From<Unary> for NodeInner

Source§

fn from(n: Unary) -> NodeInner

Converts to this type from the input type.
Source§

impl From<Var> for NodeInner

Source§

fn from(n: Var) -> NodeInner

Converts to this type from the input type.
Source§

impl Hash for NodeInner

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for NodeInner

Source§

fn eq(&self, other: &NodeInner) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for NodeInner

Source§

impl StructuralPartialEq for NodeInner

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.