macro_rules! derive_unplateable {
($t:ty) => { ... };
}Expand description
Generates Biplate and Uniplate instances for an unplateable type.
An unplateable type is one that you don’t want Uniplate to traverse inside of.
The type must implement Clone and Eq.
Consider marking a type unplateable if it has no children (e.g. String) or does not support
the derive macro, but you still need a Uniplate or Biplate implementation for it.
§Example
For example, the target of a Biplate operation must implement Uniplate.
The below example uses Biplate to get all the Names in a binary tree.
use uniplate::{derive_unplateable,Uniplate,Biplate,derive::Uniplate};
// If you don't care about the children of a type, use derive_unplateable!
#[derive(Clone,PartialEq,Eq)]
struct Name {
first: String,
last: String
}
derive_unplateable!(Name);
#[derive(Clone,PartialEq,Eq,Uniplate)]
#[uniplate()]
#[biplate(to=Name)]
enum MyTree {
Leaf(Name),
Branch(Name,Box<MyTree>,Box<MyTree>)
}
/// Gets all the names in the tree
fn names_in_tree(tree: &MyTree) -> Vec<Name> {
let names: Vec<Name> = tree.universe_bi().into_iter().collect();
names
}