pub trait TreeLike: Clone + Sized {
type NaryChildren: Clone;
// Required methods
fn nary_len(tc: &Self::NaryChildren) -> usize;
fn nary_index(tc: Self::NaryChildren, idx: usize) -> Self;
fn as_node(&self) -> Tree<Self, Self::NaryChildren>;
// Provided methods
fn n_children(&self) -> usize { ... }
fn nth_child(&self, n: usize) -> Option<Self> { ... }
fn pre_order_iter(self) -> PreOrderIter<Self> ⓘ { ... }
fn verbose_pre_order_iter(self) -> VerbosePreOrderIter<Self> ⓘ { ... }
fn post_order_iter(self) -> PostOrderIter<Self> ⓘ { ... }
fn rtl_post_order_iter(self) -> RtlPostOrderIter<Self> { ... }
}Expand description
A trait for any structure which has the shape of a Miniscript tree.
As a general rule, this should be implemented on references to nodes, rather than nodes themselves, because it provides algorithms that assume copying is cheap.
To implement this trait, you only need to implement the TreeLike::as_node,
TreeLike::nary_len and `[TreeLike::nary_index’] methods, which should
be very mechanical. Everything else is provided.
Required Associated Types§
Sourcetype NaryChildren: Clone
type NaryChildren: Clone
An abstraction over the children of n-ary nodes. Typically when
implementing the trait for &a T this will be &'a [T].
Required Methods§
Sourcefn nary_len(tc: &Self::NaryChildren) -> usize
fn nary_len(tc: &Self::NaryChildren) -> usize
Accessor for the length of a Self::NaryChildren.
Sourcefn nary_index(tc: Self::NaryChildren, idx: usize) -> Self
fn nary_index(tc: Self::NaryChildren, idx: usize) -> Self
Accessor for a specific child of a Self::NaryChildren.
§Panics
May panic if asked for an element outside of the range
0..Self::nary_len(&tc).
Sourcefn as_node(&self) -> Tree<Self, Self::NaryChildren>
fn as_node(&self) -> Tree<Self, Self::NaryChildren>
Interpret the node as an abstract node.
Provided Methods§
Sourcefn n_children(&self) -> usize
fn n_children(&self) -> usize
Accessor for the number of children this node has.
Sourcefn nth_child(&self, n: usize) -> Option<Self>
fn nth_child(&self, n: usize) -> Option<Self>
Accessor for the nth child of the node, if a child with that index exists.
Sourcefn pre_order_iter(self) -> PreOrderIter<Self> ⓘ
fn pre_order_iter(self) -> PreOrderIter<Self> ⓘ
Obtains an iterator of all the nodes rooted at the node, in pre-order.
Sourcefn verbose_pre_order_iter(self) -> VerbosePreOrderIter<Self> ⓘ
fn verbose_pre_order_iter(self) -> VerbosePreOrderIter<Self> ⓘ
Obtains a verbose iterator of all the nodes rooted at the DAG, in pre-order.
See the documentation of VerbosePreOrderIter for more information about what
this does. Essentially, if you find yourself using Self::pre_order_iter and
then adding a stack to manually track which items and their children have been
yielded, you may be better off using this iterator instead.
Sourcefn post_order_iter(self) -> PostOrderIter<Self> ⓘ
fn post_order_iter(self) -> PostOrderIter<Self> ⓘ
Obtains an iterator of all the nodes rooted at the DAG, in post order.
Each node is only yielded once, at the leftmost position that it appears in the DAG.
Sourcefn rtl_post_order_iter(self) -> RtlPostOrderIter<Self>
fn rtl_post_order_iter(self) -> RtlPostOrderIter<Self>
Obtains an iterator of all the nodes rooted at the DAG, in right-to-left post order.
This ordering is useful for “translation” algorithms which iterate over a structure, pushing translated nodes and popping children.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".