pub trait Node {
type Iter<'a>: DoubleEndedIterator<Item = &'a Self>
where Self: 'a;
// Required methods
fn name(&self) -> &str;
fn children(&self) -> Self::Iter<'_>;
}
Expand description
Represents a node in the tree.
Important as render takes a Node
as its only parameter.
§Example
use render_as_tree::Node;
struct BasicNode {
pub name: String,
pub children: Vec<BasicNode>,
}
impl BasicNode {
pub fn new(name: String) -> BasicNode {
BasicNode {
name,
children: Vec::new(),
}
}
}
impl Node for BasicNode {
type Iter<'a> = std::slice::Iter<'a, Self>;
fn name(&self) -> &str {
&self.name
}
fn children(&self) -> Self::Iter<'_> {
self.children.iter()
}
}
Required Associated Types§
Sourcetype Iter<'a>: DoubleEndedIterator<Item = &'a Self>
where
Self: 'a
type Iter<'a>: DoubleEndedIterator<Item = &'a Self> where Self: 'a
An iterator over the children of this node
Required Methods§
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.