pub struct TreeNode<T> { /* private fields */ }Expand description
A node in the tree hierarchy.
Implementations§
Source§impl<T: Clone> TreeNode<T>
impl<T: Clone> TreeNode<T>
Sourcepub fn new(label: impl Into<String>, data: T) -> Self
pub fn new(label: impl Into<String>, data: T) -> Self
Creates a new tree node with a label and data.
§Example
use envision::component::TreeNode;
let node = TreeNode::new("Documents", "/home/user/docs");
assert_eq!(node.label(), "Documents");
assert_eq!(node.data(), &"/home/user/docs");Sourcepub fn new_expanded(label: impl Into<String>, data: T) -> Self
pub fn new_expanded(label: impl Into<String>, data: T) -> Self
Creates a new node that starts expanded.
§Example
use envision::component::TreeNode;
let node: TreeNode<()> = TreeNode::new_expanded("Root", ());
assert!(node.is_expanded());Sourcepub fn set_label(&mut self, label: impl Into<String>)
pub fn set_label(&mut self, label: impl Into<String>)
Sets the node’s label.
§Example
use envision::component::TreeNode;
let mut node = TreeNode::new("Old", ());
node.set_label("New");
assert_eq!(node.label(), "New");Sourcepub fn data(&self) -> &T
pub fn data(&self) -> &T
Returns a reference to the node’s data.
§Example
use envision::component::TreeNode;
let node = TreeNode::new("Root", 42u32);
assert_eq!(node.data(), &42u32);Sourcepub fn data_mut(&mut self) -> &mut T
pub fn data_mut(&mut self) -> &mut T
Returns a mutable reference to the node’s data.
§Example
use envision::component::TreeNode;
let mut node = TreeNode::new("Root", 0u32);
*node.data_mut() = 99;
assert_eq!(node.data(), &99u32);Sourcepub fn children(&self) -> &[TreeNode<T>]
pub fn children(&self) -> &[TreeNode<T>]
Returns the children of this node.
§Example
use envision::component::TreeNode;
let mut parent = TreeNode::new("Parent", ());
parent.add_child(TreeNode::new("Child", ()));
assert_eq!(parent.children().len(), 1);Sourcepub fn children_mut(&mut self) -> &mut Vec<TreeNode<T>>
pub fn children_mut(&mut self) -> &mut Vec<TreeNode<T>>
Returns a mutable reference to the children.
§Example
use envision::component::TreeNode;
let mut node = TreeNode::new("Root", ());
node.children_mut().push(TreeNode::new("Child", ()));
assert_eq!(node.children().len(), 1);Sourcepub fn add_child(&mut self, child: TreeNode<T>)
pub fn add_child(&mut self, child: TreeNode<T>)
Adds a child node.
§Example
use envision::component::TreeNode;
let mut parent = TreeNode::new("Parent", ());
parent.add_child(TreeNode::new("Child", ()));
assert_eq!(parent.children().len(), 1);Sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Returns true if this node has children.
§Example
use envision::component::TreeNode;
let mut parent = TreeNode::new("Parent", ());
assert!(!parent.has_children());
parent.add_child(TreeNode::new("Child", ()));
assert!(parent.has_children());Sourcepub fn is_expanded(&self) -> bool
pub fn is_expanded(&self) -> bool
Returns true if this node is expanded.
§Example
use envision::component::TreeNode;
let node = TreeNode::new("Root", ());
assert!(!node.is_expanded());Sourcepub fn set_expanded(&mut self, expanded: bool)
pub fn set_expanded(&mut self, expanded: bool)
Sets the expanded state.
§Example
use envision::component::TreeNode;
let mut node = TreeNode::new("Root", ());
node.set_expanded(true);
assert!(node.is_expanded());Sourcepub fn expand(&mut self)
pub fn expand(&mut self)
Expands this node.
§Example
use envision::component::TreeNode;
let mut node = TreeNode::new("Root", ());
node.expand();
assert!(node.is_expanded());Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for TreeNode<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for TreeNode<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<T> Freeze for TreeNode<T>where
T: Freeze,
impl<T> RefUnwindSafe for TreeNode<T>where
T: RefUnwindSafe,
impl<T> Send for TreeNode<T>where
T: Send,
impl<T> Sync for TreeNode<T>where
T: Sync,
impl<T> Unpin for TreeNode<T>where
T: Unpin,
impl<T> UnsafeUnpin for TreeNode<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for TreeNode<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more