refactor: improve lifetime names

This commit is contained in:
EdJoPaTo
2024-05-13 00:33:34 +02:00
parent 04ecf5388f
commit 9dcccba31d
4 changed files with 16 additions and 16 deletions
+3 -3
View File
@@ -9,12 +9,12 @@ use ratatui::widgets::{Block, Scrollbar, ScrollbarOrientation};
use ratatui::{Frame, Terminal}; use ratatui::{Frame, Terminal};
use tui_tree_widget::{Tree, TreeItem, TreeState}; use tui_tree_widget::{Tree, TreeItem, TreeState};
struct App<'a> { struct App {
state: TreeState<&'static str>, state: TreeState<&'static str>,
items: Vec<TreeItem<'a, &'static str>>, items: Vec<TreeItem<'static, &'static str>>,
} }
impl<'a> App<'a> { impl App {
fn new() -> Self { fn new() -> Self {
Self { Self {
state: TreeState::default(), state: TreeState::default(),
+6 -6
View File
@@ -5,12 +5,12 @@ use crate::tree_item::TreeItem;
/// A flattened item of all visible [`TreeItem`]s. /// A flattened item of all visible [`TreeItem`]s.
/// ///
/// Generated via [`TreeState::flatten`](crate::TreeState::flatten). /// Generated via [`TreeState::flatten`](crate::TreeState::flatten).
pub struct Flattened<'a, Identifier> { pub struct Flattened<'text, Identifier> {
pub identifier: Vec<Identifier>, pub identifier: Vec<Identifier>,
pub item: &'a TreeItem<'a, Identifier>, pub item: &'text TreeItem<'text, Identifier>,
} }
impl<'a, Identifier> Flattened<'a, Identifier> { impl<Identifier> Flattened<'_, Identifier> {
/// Zero based depth. Depth 0 means 0 indentation. /// Zero based depth. Depth 0 means 0 indentation.
#[must_use] #[must_use]
pub fn depth(&self) -> usize { pub fn depth(&self) -> usize {
@@ -22,11 +22,11 @@ impl<'a, Identifier> Flattened<'a, Identifier> {
/// ///
/// `current` starts empty: `&[]` /// `current` starts empty: `&[]`
#[must_use] #[must_use]
pub fn flatten<'a, Identifier>( pub fn flatten<'text, Identifier>(
opened: &HashSet<Vec<Identifier>>, opened: &HashSet<Vec<Identifier>>,
items: &'a [TreeItem<'a, Identifier>], items: &'text [TreeItem<'text, Identifier>],
current: &[Identifier], current: &[Identifier],
) -> Vec<Flattened<'a, Identifier>> ) -> Vec<Flattened<'text, Identifier>>
where where
Identifier: Clone + PartialEq + Eq + core::hash::Hash, Identifier: Clone + PartialEq + Eq + core::hash::Hash,
{ {
+2 -2
View File
@@ -169,7 +169,7 @@ fn tree_new_errors_with_duplicate_identifiers() {
Tree::new(vec![item, another]).unwrap(); Tree::new(vec![item, another]).unwrap();
} }
impl<'a, Identifier> StatefulWidget for Tree<'a, Identifier> impl<Identifier> StatefulWidget for Tree<'_, Identifier>
where where
Identifier: Clone + PartialEq + Eq + core::hash::Hash, Identifier: Clone + PartialEq + Eq + core::hash::Hash,
{ {
@@ -332,7 +332,7 @@ where
} }
} }
impl<'a, Identifier> Widget for Tree<'a, Identifier> impl<Identifier> Widget for Tree<'_, Identifier>
where where
Identifier: Clone + Default + Eq + core::hash::Hash, Identifier: Clone + Default + Eq + core::hash::Hash,
{ {
+5 -5
View File
@@ -34,13 +34,13 @@ use ratatui::text::Text;
/// # Ok::<(), std::io::Error>(()) /// # Ok::<(), std::io::Error>(())
/// ``` /// ```
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct TreeItem<'a, Identifier> { pub struct TreeItem<'text, Identifier> {
pub(super) identifier: Identifier, pub(super) identifier: Identifier,
pub(super) text: Text<'a>, pub(super) text: Text<'text>,
pub(super) children: Vec<Self>, pub(super) children: Vec<Self>,
} }
impl<'a, Identifier> TreeItem<'a, Identifier> impl<'text, Identifier> TreeItem<'text, Identifier>
where where
Identifier: Clone + PartialEq + Eq + core::hash::Hash, Identifier: Clone + PartialEq + Eq + core::hash::Hash,
{ {
@@ -48,7 +48,7 @@ where
#[must_use] #[must_use]
pub fn new_leaf<T>(identifier: Identifier, text: T) -> Self pub fn new_leaf<T>(identifier: Identifier, text: T) -> Self
where where
T: Into<Text<'a>>, T: Into<Text<'text>>,
{ {
Self { Self {
identifier, identifier,
@@ -64,7 +64,7 @@ where
/// Errors when there are duplicate identifiers in the children. /// Errors when there are duplicate identifiers in the children.
pub fn new<T>(identifier: Identifier, text: T, children: Vec<Self>) -> std::io::Result<Self> pub fn new<T>(identifier: Identifier, text: T, children: Vec<Self>) -> std::io::Result<Self>
where where
T: Into<Text<'a>>, T: Into<Text<'text>>,
{ {
let identifiers = children let identifiers = children
.iter() .iter()