pub struct TreeItem<T>{ /* private fields */ }Expand description
One item inside a Tree.
Can have zero or more children.
§identifier
The identifier is used to keep the state like the currently selected or opened TreeItems in the TreeState.
It needs to be unique among its siblings but can be used again on parent or child TreeItems.
A common example would be a filename which has to be unique in its directory while it can exist in another.
The text can be different from its identifier.
To repeat the filename analogy: File browsers sometimes hide file extensions.
The filename main.rs is the identifier while it’s shown as main.
Two files main.rs and main.toml can exist in the same directory and can both be displayed as main but their identifier is different.
Just like every file in a file system can be uniquely identified with its file and directory names each TreeItem in a Tree can be with these identifiers.
As an example the following two identifiers describe the main file in a Rust cargo project: vec!["src", "main.rs"].
The identifier does not need to be a String and is therefore generic.
Until version 0.14 this crate used usize and indices.
This might still be perfect for your use case.
§Example
let a = TreeItem::new_leaf("Leaf");
let b = TreeItem::new("Root", vec![a])?;Implementations§
Source§impl<T> TreeItem<T>
impl<T> TreeItem<T>
Sourcepub fn new(content: T, children: Vec<Self>) -> Result<Self>
pub fn new(content: T, children: Vec<Self>) -> Result<Self>
Create a new TreeItem with children.
§Errors
Errors when there are duplicate identifiers in the children.
Sourcepub const fn identifier(&self) -> u64
pub const fn identifier(&self) -> u64
Get a reference to the identifier.
pub fn children(&self) -> &[Self]
Sourcepub fn child_mut(&mut self, index: usize) -> Option<&mut Self>
pub fn child_mut(&mut self, index: usize) -> Option<&mut Self>
Get a mutable reference to a child by index.
When you choose to change the identifier the TreeState might not work as expected afterward.
pub fn height(&self) -> usize
Trait Implementations§
impl<T> Eq for TreeItem<T>
impl<T> StructuralPartialEq for TreeItem<T>
Auto Trait Implementations§
impl<T> Freeze for TreeItem<T>where
T: Freeze,
impl<T> RefUnwindSafe for TreeItem<T>where
T: RefUnwindSafe,
impl<T> Send for TreeItem<T>where
T: Send,
impl<T> Sync for TreeItem<T>where
T: Sync,
impl<T> Unpin for TreeItem<T>where
T: Unpin,
impl<T> UnwindSafe for TreeItem<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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>
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>
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