pub trait Uniplate{
// 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§
Provided Methods§
Sourcefn descend(&self, op: &impl Fn(Self) -> Self) -> Self
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.
Sourcefn universe(&self) -> VecDeque<Self>
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.
Sourcefn children(&self) -> VecDeque<Self>
fn children(&self) -> VecDeque<Self>
Gets the direct children (maximal substructures) of a node.
Sourcefn with_children(&self, children: VecDeque<Self>) -> Self
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().
Sourcefn transform(&self, f: &impl Fn(Self) -> Self) -> Self
fn transform(&self, f: &impl Fn(Self) -> Self) -> Self
Applies the given function to all nodes bottom up.
Sourcefn rewrite(&self, f: &impl Fn(Self) -> Option<Self>) -> Self
fn rewrite(&self, f: &impl Fn(Self) -> Option<Self>) -> Self
Rewrites by applying a rule everywhere it can.
Sourcefn cata<T>(&self, op: &impl Fn(Self, VecDeque<T>) -> T) -> T
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
Sourcefn holes(&self) -> impl Iterator<Item = (Self, impl Fn(Self) -> Self)>
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.
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.