feat(TreeItem): Added PartialEq and Eq constraints to the types that can be passed to the TreeItem struct

This commit is contained in:
2024-11-15 14:40:44 -07:00
parent 959b60de32
commit b0d8d9f0bf
4 changed files with 11 additions and 11 deletions
+3 -3
View File
@@ -10,7 +10,7 @@ use std::hash::Hash;
#[must_use]
pub struct Flattened<'a, T>
where
T: ToText + Clone + Default + Display + Hash,
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
{
pub identifier: Vec<u64>,
pub item: &'a TreeItem<T>,
@@ -18,7 +18,7 @@ where
impl<'a, T> Flattened<'a, T>
where
T: ToText + Clone + Default + Display + Hash,
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
{
/// Zero based depth. Depth 0 means top level with 0 indentation.
#[must_use]
@@ -37,7 +37,7 @@ pub fn flatten<'a, T>(
current: &[u64],
) -> Vec<Flattened<'a, T>>
where
T: ToText + Clone + Default + Display + Hash,
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
{
let mut result = Vec::new();
for item in items {
+4 -4
View File
@@ -53,7 +53,7 @@ mod tree_state;
#[derive(Debug, Clone)]
pub struct Tree<'a, T>
where
T: ToText + Clone + Default + Display + Hash,
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
{
items: &'a [TreeItem<T>],
@@ -77,7 +77,7 @@ where
impl<'a, T> Tree<'a, T>
where
T: ToText + Clone + Default + Display + Hash,
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
{
/// Create a new `Tree`.
///
@@ -167,7 +167,7 @@ fn tree_new_errors_with_duplicate_identifiers() {
impl<'a, T> StatefulWidget for Tree<'a, T>
where
T: ToText + Clone + Default + Display + Hash,
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
{
type State = TreeState;
@@ -336,7 +336,7 @@ where
impl<'a, T> Widget for Tree<'a, T>
where
T: ToText + Clone + Default + Display + Hash,
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
{
fn render(self, area: Rect, buf: &mut Buffer) {
let mut state = TreeState::default();
+3 -3
View File
@@ -34,10 +34,10 @@ use std::hash::{DefaultHasher, Hash, Hasher};
/// let b = TreeItem::new("Root", vec![a])?;
/// # Ok::<(), std::io::Error>(())
/// ```
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TreeItem<T>
where
T: ToText + Clone + Default + Display + Hash,
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
{
pub(super) identifier: u64,
pub(super) content: T,
@@ -46,7 +46,7 @@ where
impl<T> TreeItem<T>
where
T: ToText + Clone + Default + Display + Hash,
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
{
/// Create a new `TreeItem` with children.
///
+1 -1
View File
@@ -58,7 +58,7 @@ impl TreeState {
#[must_use]
pub fn flatten<'a, T>(&self, items: &'a [TreeItem<T>]) -> Vec<Flattened<'a, T>>
where
T: ToText + Clone + Default + Display + Hash,
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
{
flatten(&self.opened, items, &[])
}