Skip to main content

TreeLike

Trait TreeLike 

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

Source

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§

Source

fn nary_len(tc: &Self::NaryChildren) -> usize

Accessor for the length of a Self::NaryChildren.

Source

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

Source

fn as_node(&self) -> Tree<Self, Self::NaryChildren>

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.

Source

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".

Implementations on Foreign Types§

Source§

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

Source§

type NaryChildren = &'a [Arc<Miniscript<Pk, Ctx>>]

Source§

fn nary_len(tc: &Self::NaryChildren) -> usize

Source§

fn nary_index(tc: Self::NaryChildren, idx: usize) -> Self

Source§

fn as_node(&self) -> Tree<Self, Self::NaryChildren>

Source§

impl<'a, Pk: MiniscriptKey> TreeLike for &'a Arc<Policy<Pk>>

Source§

type NaryChildren = TreeChildren<'a, Pk>

Source§

fn nary_len(tc: &Self::NaryChildren) -> usize

Source§

fn nary_index(tc: Self::NaryChildren, idx: usize) -> Self

Source§

fn as_node(&self) -> Tree<Self, Self::NaryChildren>

Source§

impl<'a, Pk: MiniscriptKey> TreeLike for &'a Arc<Policy<Pk>>

Source§

type NaryChildren = &'a [Arc<Policy<Pk>>]

Source§

fn nary_len(tc: &Self::NaryChildren) -> usize

Source§

fn nary_index(tc: Self::NaryChildren, idx: usize) -> Self

Source§

fn as_node(&self) -> Tree<Self, Self::NaryChildren>

Implementors§

Source§

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

Source§

type NaryChildren = &'a [Arc<Miniscript<Pk, Ctx>>]

Source§

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

Source§

type NaryChildren = &'a [Arc<Miniscript<Pk, Ctx>>]

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§

type NaryChildren = &'a [Arc<Policy<Pk>>]