pub struct TreeBuilder { /* private fields */ }Expand description
Builds a RecursiveTree by appending nodes bottom-up.
Using TreeBuilder avoids manual index arithmetic when constructing CoreExpr trees.
§Example
use tidepool_repr::{TreeBuilder, CoreFrame, Literal, VarId};
let mut b = TreeBuilder::new();
let x = b.push(CoreFrame::Var(VarId(1)));
let lit = b.push(CoreFrame::Lit(Literal::LitInt(42)));
let app = b.push(CoreFrame::App { fun: x, arg: lit });
let expr = b.build();
assert_eq!(expr.nodes.len(), 3);Implementations§
Source§impl TreeBuilder
impl TreeBuilder
Sourcepub fn push_tree(&mut self, other: TreeBuilder) -> usize
pub fn push_tree(&mut self, other: TreeBuilder) -> usize
Append all nodes from another builder, offsetting indices. Returns the offset of the first added node.
Sourcepub fn build(self) -> RecursiveTree<CoreFrame<usize>>
pub fn build(self) -> RecursiveTree<CoreFrame<usize>>
Finish building, return the tree.
Trait Implementations§
Source§impl Clone for TreeBuilder
impl Clone for TreeBuilder
Source§fn clone(&self) -> TreeBuilder
fn clone(&self) -> TreeBuilder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TreeBuilder
impl Debug for TreeBuilder
Auto Trait Implementations§
impl Freeze for TreeBuilder
impl RefUnwindSafe for TreeBuilder
impl Send for TreeBuilder
impl Sync for TreeBuilder
impl Unpin for TreeBuilder
impl UnsafeUnpin for TreeBuilder
impl UnwindSafe for TreeBuilder
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