Trait miniscript::iter::TreeLike

source ·
pub trait TreeLike: Clone + Sized {
    // Required method
    fn as_node(&self) -> Tree<Self>;

    // 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>  { ... }
}
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 method, which will usually be very mechanical. Everything else is provided. However, to avoid allocations, it may make sense to also implement TreeLike::n_children and TreeLike::nth_child because the default implementations will allocate vectors for n-ary nodes.

Required Methods§

source

fn as_node(&self) -> Tree<Self>

Interpret the node as an abstract node.

Provided Methods§

source

fn n_children(&self) -> usize

Accessor for the number of children this node has.

source

fn nth_child(&self, n: usize) -> Option<Self>

Accessor for the nth child of the node, if a child with that index exists.

source

fn pre_order_iter(self) -> PreOrderIter<Self>

Obtains an iterator of all the nodes rooted at the node, in pre-order.

source

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.

source

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<Pk: MiniscriptKey> TreeLike for Arc<Policy<Pk>>

source§

fn as_node(&self) -> Tree<Self>

source§

impl<Pk: MiniscriptKey> TreeLike for Arc<Policy<Pk>>

source§

fn as_node(&self) -> Tree<Self>

source§

impl<Pk: MiniscriptKey, Ctx: ScriptContext> TreeLike for Arc<Miniscript<Pk, Ctx>>

source§

fn as_node(&self) -> Tree<Self>

Implementors§

source§

impl<'a, Pk: MiniscriptKey> TreeLike for &'a miniscript::policy::concrete::Policy<Pk>

source§

impl<'a, Pk: MiniscriptKey> TreeLike for &'a miniscript::policy::semantic::Policy<Pk>

source§

impl<'a, Pk: MiniscriptKey, Ctx: ScriptContext> TreeLike for &'a Miniscript<Pk, Ctx>