Trait Uniplate

Source
pub trait Uniplate
where Self: Sized + Clone + Eq + 'static,
{ // Required method fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>); // Provided methods fn descend(&self, op: &impl Fn(Self) -> Self) -> Self { ... } fn universe(&self) -> VecDeque<Self> { ... } fn children(&self) -> VecDeque<Self> { ... } fn with_children(&self, children: VecDeque<Self>) -> Self { ... } fn transform(&self, f: &impl Fn(Self) -> Self) -> Self { ... } fn rewrite(&self, f: &impl Fn(Self) -> Option<Self>) -> Self { ... } fn cata<T>(&self, op: &impl Fn(Self, VecDeque<T>) -> T) -> T { ... } fn holes(&self) -> impl Iterator<Item = (Self, impl Fn(Self) -> Self)> { ... } fn contexts(&self) -> impl Iterator<Item = (Self, impl Fn(Self) -> Self)> { ... } }
Expand description

Uniplate for type T operates over all values of type T within T.

Required Methods§

Source

fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)

Definition of a Uniplate.

This method is only useful for defining a Uniplate.

Provided Methods§

Source

fn descend(&self, op: &impl Fn(Self) -> Self) -> Self

Applies a function to all direct children of this

Consider using transform instead, as it does bottom-up transformation of the entire tree.

Source

fn universe(&self) -> VecDeque<Self>

Gets all children of a node, including itself and all children.

Universe does a preorder traversal: it returns a given node first, followed by its children from left to right.

Source

fn children(&self) -> VecDeque<Self>

Gets the direct children (maximal substructures) of a node.

Source

fn with_children(&self, children: VecDeque<Self>) -> Self

Reconstructs the node with the given children.

§Panics

If there are a different number of children given as there were originally returned by children().

Source

fn transform(&self, f: &impl Fn(Self) -> Self) -> Self

Applies the given function to all nodes bottom up.

Source

fn rewrite(&self, f: &impl Fn(Self) -> Option<Self>) -> Self

Rewrites by applying a rule everywhere it can.

Source

fn cata<T>(&self, op: &impl Fn(Self, VecDeque<T>) -> T) -> T

Performs a fold-like computation on each value.

Working from the bottom up, this applies the given callback function to each nested component.

Unlike transform, this returns an arbitrary type, and is not limited to T -> T transformations. In other words, it can transform a type into a new one.

The meaning of the callback function is the following:

f(element_to_fold, folded_children) -> folded_element

Source

fn holes(&self) -> impl Iterator<Item = (Self, impl Fn(Self) -> Self)>

Returns an iterator over all direct children of the input, paired with a function that “fills the hole” where the child was with a new value.

Source

fn contexts(&self) -> impl Iterator<Item = (Self, impl Fn(Self) -> Self)>

Returns an iterator over the universe of the input, paired with a function that “fills the hole” where the child was with a new value.

The universe equivalent of holes.

To efficiently update multiple values in a single traversal, use Zipper instead.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Uniplate for i8

Source§

fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)

Source§

impl Uniplate for i16

Source§

fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)

Source§

impl Uniplate for i32

Source§

fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)

Source§

impl Uniplate for i64

Source§

fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)

Source§

impl Uniplate for i128

Source§

fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)

Source§

impl Uniplate for u8

Source§

fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)

Source§

impl Uniplate for u16

Source§

fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)

Source§

impl Uniplate for u32

Source§

fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)

Source§

impl Uniplate for u64

Source§

fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)

Source§

impl Uniplate for u128

Source§

fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)

Source§

impl Uniplate for String

Source§

fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)

Source§

impl<T> Uniplate for Option<T>
where T: Uniplate + Biplate<Option<T>>,

Source§

fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)

Source§

impl<T> Uniplate for VecDeque<T>
where T: Clone + Eq + Uniplate + Sized + 'static,

Source§

fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)

Source§

impl<T> Uniplate for Vec<T>
where T: Clone + Eq + Uniplate + Sized + 'static,

Source§

fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)

Implementors§