refactor(TreeItem): simplify with Self

This commit is contained in:
EdJoPaTo
2024-05-04 16:13:17 +02:00
parent 202e8d874c
commit 775e5cc4ef
+9 -12
View File
@@ -39,7 +39,7 @@ pub struct TreeItem<'a, Identifier> {
pub(super) identifier: Identifier, pub(super) identifier: Identifier,
pub(super) text: Text<'a>, pub(super) text: Text<'a>,
pub(super) style: Style, pub(super) style: Style,
pub(super) children: Vec<TreeItem<'a, Identifier>>, pub(super) children: Vec<Self>,
} }
impl<'a, Identifier> TreeItem<'a, Identifier> impl<'a, Identifier> TreeItem<'a, Identifier>
@@ -89,7 +89,7 @@ where
} }
#[must_use] #[must_use]
pub fn children(&self) -> &[TreeItem<Identifier>] { pub fn children(&self) -> &[Self] {
&self.children &self.children
} }
@@ -145,26 +145,23 @@ impl TreeItem<'static, &'static str> {
#[cfg(test)] #[cfg(test)]
pub(crate) fn example() -> Vec<Self> { pub(crate) fn example() -> Vec<Self> {
vec![ vec![
TreeItem::new_leaf("a", "Alfa"), Self::new_leaf("a", "Alfa"),
TreeItem::new( Self::new(
"b", "b",
"Bravo", "Bravo",
vec![ vec![
TreeItem::new_leaf("c", "Charlie"), Self::new_leaf("c", "Charlie"),
TreeItem::new( Self::new(
"d", "d",
"Delta", "Delta",
vec![ vec![Self::new_leaf("e", "Echo"), Self::new_leaf("f", "Foxtrot")],
TreeItem::new_leaf("e", "Echo"),
TreeItem::new_leaf("f", "Foxtrot"),
],
) )
.expect("all item identifiers are unique"), .expect("all item identifiers are unique"),
TreeItem::new_leaf("g", "Golf"), Self::new_leaf("g", "Golf"),
], ],
) )
.expect("all item identifiers are unique"), .expect("all item identifiers are unique"),
TreeItem::new_leaf("h", "Hotel"), Self::new_leaf("h", "Hotel"),
] ]
} }
} }