pub struct TreeItem<'a, Identifier> { /* private fields */ }
Expand description

One item inside a Tree.

Can have zero or more children.

§Identifier

The generic argument 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 its 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("l", "Leaf");
let b = TreeItem::new("r", "Root", vec![a])?;

Implementations§

source§

impl<'a, Identifier> Item<'a, Identifier>
where Identifier: Clone + PartialEq + Eq + Hash,

source

pub fn new_leaf<T>(identifier: Identifier, text: T) -> Self
where T: Into<Text<'a>>,

Create a new TreeItem without children.

source

pub fn new<T>( identifier: Identifier, text: T, children: Vec<Item<'a, Identifier>> ) -> Result<Self>
where T: Into<Text<'a>>,

Create a new TreeItem with children.

§Errors

Errors when there are duplicate identifiers in the children.

source

pub fn children(&self) -> &[Item<'_, Identifier>]

source

pub fn child(&self, index: usize) -> Option<&Self>

Get a reference to a child by index.

source

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 afterwards.

source

pub fn height(&self) -> usize

source

pub const fn style(self, style: Style) -> Self

source

pub fn add_child(&mut self, child: Item<'a, Identifier>) -> Result<()>

Add a child to the TreeItem.

§Errors

Errors when the identifier of the child already exists in the children.

Trait Implementations§

source§

impl<'a, Identifier: Clone> Clone for Item<'a, Identifier>

source§

fn clone(&self) -> Item<'a, Identifier>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a, Identifier: Debug> Debug for Item<'a, Identifier>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, Identifier> RefUnwindSafe for Item<'a, Identifier>
where Identifier: RefUnwindSafe,

§

impl<'a, Identifier> Send for Item<'a, Identifier>
where Identifier: Send,

§

impl<'a, Identifier> Sync for Item<'a, Identifier>
where Identifier: Sync,

§

impl<'a, Identifier> Unpin for Item<'a, Identifier>
where Identifier: Unpin,

§

impl<'a, Identifier> UnwindSafe for Item<'a, Identifier>
where Identifier: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.