refactor(lint): improve and adapt to lints
This commit is contained in:
+3
-2
@@ -1,5 +1,3 @@
|
|||||||
#![allow(clippy::implicit_hasher)]
|
|
||||||
|
|
||||||
use crate::identifier::{TreeIdentifier, TreeIdentifierVec};
|
use crate::identifier::{TreeIdentifier, TreeIdentifierVec};
|
||||||
use crate::TreeItem;
|
use crate::TreeItem;
|
||||||
|
|
||||||
@@ -9,16 +7,19 @@ pub struct Flattened<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Flattened<'a> {
|
impl<'a> Flattened<'a> {
|
||||||
|
#[must_use]
|
||||||
pub fn depth(&self) -> usize {
|
pub fn depth(&self) -> usize {
|
||||||
self.identifier.len() - 1
|
self.identifier.len() - 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a flat list of all visible [`TreeItem`s](TreeItem)
|
/// 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>> {
|
pub fn flatten<'a>(opened: &[TreeIdentifierVec], items: &'a [TreeItem<'a>]) -> Vec<Flattened<'a>> {
|
||||||
internal(opened, items, &[])
|
internal(opened, items, &[])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
fn internal<'a>(
|
fn internal<'a>(
|
||||||
opened: &[TreeIdentifierVec],
|
opened: &[TreeIdentifierVec],
|
||||||
items: &'a [TreeItem<'a>],
|
items: &'a [TreeItem<'a>],
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ pub type TreeIdentifierVec = Vec<usize>;
|
|||||||
/// assert_eq!(branch, []);
|
/// assert_eq!(branch, []);
|
||||||
/// assert_eq!(leaf, None);
|
/// assert_eq!(leaf, None);
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub const fn get_without_leaf(identifier: TreeIdentifier) -> (TreeIdentifier, Option<usize>) {
|
pub const fn get_without_leaf(identifier: TreeIdentifier) -> (TreeIdentifier, Option<usize>) {
|
||||||
match identifier {
|
match identifier {
|
||||||
[branch @ .., leaf] => (branch, Some(*leaf)),
|
[branch @ .., leaf] => (branch, Some(*leaf)),
|
||||||
|
|||||||
+10
-1
@@ -1,4 +1,3 @@
|
|||||||
#![allow(clippy::must_use_candidate)]
|
|
||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
@@ -34,14 +33,17 @@ pub struct TreeState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TreeState {
|
impl TreeState {
|
||||||
|
#[must_use]
|
||||||
pub const fn get_offset(&self) -> usize {
|
pub const fn get_offset(&self) -> usize {
|
||||||
self.offset
|
self.offset
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn get_all_opened(&self) -> Vec<TreeIdentifierVec> {
|
pub fn get_all_opened(&self) -> Vec<TreeIdentifierVec> {
|
||||||
self.opened.iter().cloned().collect()
|
self.opened.iter().cloned().collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn selected(&self) -> Vec<usize> {
|
pub fn selected(&self) -> Vec<usize> {
|
||||||
self.selected.clone()
|
self.selected.clone()
|
||||||
}
|
}
|
||||||
@@ -183,6 +185,7 @@ pub struct TreeItem<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TreeItem<'a> {
|
impl<'a> TreeItem<'a> {
|
||||||
|
#[must_use]
|
||||||
pub fn new_leaf<T>(text: T) -> Self
|
pub fn new_leaf<T>(text: T) -> Self
|
||||||
where
|
where
|
||||||
T: Into<Text<'a>>,
|
T: Into<Text<'a>>,
|
||||||
@@ -194,6 +197,7 @@ impl<'a> TreeItem<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn new<T, Children>(text: T, children: Children) -> Self
|
pub fn new<T, Children>(text: T, children: Children) -> Self
|
||||||
where
|
where
|
||||||
T: Into<Text<'a>>,
|
T: Into<Text<'a>>,
|
||||||
@@ -206,18 +210,22 @@ impl<'a> TreeItem<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn children(&self) -> &[TreeItem] {
|
pub fn children(&self) -> &[TreeItem] {
|
||||||
&self.children
|
&self.children
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn child(&self, index: usize) -> Option<&Self> {
|
pub fn child(&self, index: usize) -> Option<&Self> {
|
||||||
self.children.get(index)
|
self.children.get(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn child_mut(&mut self, index: usize) -> Option<&mut Self> {
|
pub fn child_mut(&mut self, index: usize) -> Option<&mut Self> {
|
||||||
self.children.get_mut(index)
|
self.children.get_mut(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn height(&self) -> usize {
|
pub fn height(&self) -> usize {
|
||||||
self.text.height()
|
self.text.height()
|
||||||
}
|
}
|
||||||
@@ -283,6 +291,7 @@ pub struct Tree<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Tree<'a> {
|
impl<'a> Tree<'a> {
|
||||||
|
#[must_use]
|
||||||
pub fn new<T>(items: T) -> Self
|
pub fn new<T>(items: T) -> Self
|
||||||
where
|
where
|
||||||
T: Into<Vec<TreeItem<'a>>>,
|
T: Into<Vec<TreeItem<'a>>>,
|
||||||
|
|||||||
Reference in New Issue
Block a user