refactor(lint): improve and adapt to lints

This commit is contained in:
EdJoPaTo
2023-05-22 11:50:09 +02:00
parent 4d3a1eac30
commit 8a53caced7
3 changed files with 14 additions and 3 deletions
+3 -2
View File
@@ -1,5 +1,3 @@
#![allow(clippy::implicit_hasher)]
use crate::identifier::{TreeIdentifier, TreeIdentifierVec};
use crate::TreeItem;
@@ -9,16 +7,19 @@ pub struct Flattened<'a> {
}
impl<'a> Flattened<'a> {
#[must_use]
pub fn depth(&self) -> usize {
self.identifier.len() - 1
}
}
/// Get a flat list of all visible [`TreeItem`s](TreeItem)
#[must_use]
pub fn flatten<'a>(opened: &[TreeIdentifierVec], items: &'a [TreeItem<'a>]) -> Vec<Flattened<'a>> {
internal(opened, items, &[])
}
#[must_use]
fn internal<'a>(
opened: &[TreeIdentifierVec],
items: &'a [TreeItem<'a>],
+1
View File
@@ -23,6 +23,7 @@ pub type TreeIdentifierVec = Vec<usize>;
/// assert_eq!(branch, []);
/// assert_eq!(leaf, None);
/// ```
#[must_use]
pub const fn get_without_leaf(identifier: TreeIdentifier) -> (TreeIdentifier, Option<usize>) {
match identifier {
[branch @ .., leaf] => (branch, Some(*leaf)),
+10 -1
View File
@@ -1,4 +1,3 @@
#![allow(clippy::must_use_candidate)]
#![forbid(unsafe_code)]
use std::collections::HashSet;
@@ -34,14 +33,17 @@ pub struct TreeState {
}
impl TreeState {
#[must_use]
pub const fn get_offset(&self) -> usize {
self.offset
}
#[must_use]
pub fn get_all_opened(&self) -> Vec<TreeIdentifierVec> {
self.opened.iter().cloned().collect()
}
#[must_use]
pub fn selected(&self) -> Vec<usize> {
self.selected.clone()
}
@@ -183,6 +185,7 @@ pub struct TreeItem<'a> {
}
impl<'a> TreeItem<'a> {
#[must_use]
pub fn new_leaf<T>(text: T) -> Self
where
T: Into<Text<'a>>,
@@ -194,6 +197,7 @@ impl<'a> TreeItem<'a> {
}
}
#[must_use]
pub fn new<T, Children>(text: T, children: Children) -> Self
where
T: Into<Text<'a>>,
@@ -206,18 +210,22 @@ impl<'a> TreeItem<'a> {
}
}
#[must_use]
pub fn children(&self) -> &[TreeItem] {
&self.children
}
#[must_use]
pub fn child(&self, index: usize) -> Option<&Self> {
self.children.get(index)
}
#[must_use]
pub fn child_mut(&mut self, index: usize) -> Option<&mut Self> {
self.children.get_mut(index)
}
#[must_use]
pub fn height(&self) -> usize {
self.text.height()
}
@@ -283,6 +291,7 @@ pub struct Tree<'a> {
}
impl<'a> Tree<'a> {
#[must_use]
pub fn new<T>(items: T) -> Self
where
T: Into<Vec<TreeItem<'a>>>,