uniplate

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: Arc<dyn Fn(Self) -> Self>) -> Self { ... } fn universe(&self) -> Vector<Self> { ... } fn children(&self) -> Vector<Self> { ... } fn with_children(&self, children: Vector<Self>) -> Self { ... } fn transform(&self, f: Arc<dyn Fn(Self) -> Self>) -> Self { ... } fn rewrite(&self, f: Arc<dyn Fn(Self) -> Option<Self>>) -> Self { ... } fn cata<T>(&self, op: Arc<dyn Fn(Self, Vec<T>) -> T>) -> T { ... } fn holes(&self) -> impl Iterator<Item = (Self, Arc<dyn Fn(Self) -> Self>)> { ... } fn contexts( &self, ) -> impl Iterator<Item = (Self, Arc<dyn 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>)

Provided Methods§

Source

fn descend(&self, op: Arc<dyn Fn(Self) -> Self>) -> Self

Source

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

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

Source

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

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

Source

fn with_children(&self, children: Vector<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: Arc<dyn Fn(Self) -> Self>) -> Self

Applies the given rule to all nodes bottom up.

Source

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

Rewrites by applying a rule everywhere it can.

Source

fn cata<T>(&self, op: Arc<dyn Fn(Self, Vec<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, Arc<dyn 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, Arc<dyn Fn(Self) -> Self>)>

The universe() equivalent for holes.

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

Source§

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

Source§

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

Implementors§