From 8c43147be8e257be4bc59f142881a0b65492cfbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joey=20Ezechi=C3=ABls?= Date: Sat, 1 May 2021 14:18:37 +0200 Subject: [PATCH] Improve API (#3) * Introduce TreeItem::{child, child_mut}() accessors * Add docstrings for TreeState::{open, close}() --- src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) mode change 100644 => 100755 src/lib.rs diff --git a/src/lib.rs b/src/lib.rs old mode 100644 new mode 100755 index c8e86d5..ae7cded --- a/src/lib.rs +++ b/src/lib.rs @@ -49,6 +49,9 @@ impl TreeState { } } + /// Open a tree node. + /// Returns `true` if the node was closed and has been opened. + /// Returns `false` if the node was already open. pub fn open(&mut self, identifier: TreeIdentifierVec) -> bool { if identifier.is_empty() { false @@ -57,6 +60,9 @@ impl TreeState { } } + /// Close a tree node. + /// Returns `true` if the node was open and has been closed. + /// Returns `false` if the node was already closed. pub fn close(&mut self, identifier: TreeIdentifier) -> bool { self.opened.remove(identifier) } @@ -105,6 +111,14 @@ impl<'a> TreeItem<'a> { } } + pub fn child(&self, index: usize) -> Option<&Self> { + self.children.get(index) + } + + pub fn child_mut(&mut self, index: usize) -> Option<&mut Self> { + self.children.get_mut(index) + } + pub fn height(&self) -> usize { self.text.height() }