feat(TreeItem): Added PartialEq and Eq constraints to the types that can be passed to the TreeItem struct
This commit is contained in:
+3
-3
@@ -10,7 +10,7 @@ use std::hash::Hash;
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub struct Flattened<'a, T>
|
pub struct Flattened<'a, T>
|
||||||
where
|
where
|
||||||
T: ToText + Clone + Default + Display + Hash,
|
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
|
||||||
{
|
{
|
||||||
pub identifier: Vec<u64>,
|
pub identifier: Vec<u64>,
|
||||||
pub item: &'a TreeItem<T>,
|
pub item: &'a TreeItem<T>,
|
||||||
@@ -18,7 +18,7 @@ where
|
|||||||
|
|
||||||
impl<'a, T> Flattened<'a, T>
|
impl<'a, T> Flattened<'a, T>
|
||||||
where
|
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.
|
/// Zero based depth. Depth 0 means top level with 0 indentation.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
@@ -37,7 +37,7 @@ pub fn flatten<'a, T>(
|
|||||||
current: &[u64],
|
current: &[u64],
|
||||||
) -> Vec<Flattened<'a, T>>
|
) -> Vec<Flattened<'a, T>>
|
||||||
where
|
where
|
||||||
T: ToText + Clone + Default + Display + Hash,
|
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
|
||||||
{
|
{
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
for item in items {
|
for item in items {
|
||||||
|
|||||||
+4
-4
@@ -53,7 +53,7 @@ mod tree_state;
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Tree<'a, T>
|
pub struct Tree<'a, T>
|
||||||
where
|
where
|
||||||
T: ToText + Clone + Default + Display + Hash,
|
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
|
||||||
{
|
{
|
||||||
items: &'a [TreeItem<T>],
|
items: &'a [TreeItem<T>],
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ where
|
|||||||
|
|
||||||
impl<'a, T> Tree<'a, T>
|
impl<'a, T> Tree<'a, T>
|
||||||
where
|
where
|
||||||
T: ToText + Clone + Default + Display + Hash,
|
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
|
||||||
{
|
{
|
||||||
/// Create a new `Tree`.
|
/// Create a new `Tree`.
|
||||||
///
|
///
|
||||||
@@ -167,7 +167,7 @@ fn tree_new_errors_with_duplicate_identifiers() {
|
|||||||
|
|
||||||
impl<'a, T> StatefulWidget for Tree<'a, T>
|
impl<'a, T> StatefulWidget for Tree<'a, T>
|
||||||
where
|
where
|
||||||
T: ToText + Clone + Default + Display + Hash,
|
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
|
||||||
{
|
{
|
||||||
type State = TreeState;
|
type State = TreeState;
|
||||||
|
|
||||||
@@ -336,7 +336,7 @@ where
|
|||||||
|
|
||||||
impl<'a, T> Widget for Tree<'a, T>
|
impl<'a, T> Widget for Tree<'a, T>
|
||||||
where
|
where
|
||||||
T: ToText + Clone + Default + Display + Hash,
|
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
|
||||||
{
|
{
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||||
let mut state = TreeState::default();
|
let mut state = TreeState::default();
|
||||||
|
|||||||
+3
-3
@@ -34,10 +34,10 @@ use std::hash::{DefaultHasher, Hash, Hasher};
|
|||||||
/// let b = TreeItem::new("Root", vec![a])?;
|
/// let b = TreeItem::new("Root", vec![a])?;
|
||||||
/// # Ok::<(), std::io::Error>(())
|
/// # Ok::<(), std::io::Error>(())
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct TreeItem<T>
|
pub struct TreeItem<T>
|
||||||
where
|
where
|
||||||
T: ToText + Clone + Default + Display + Hash,
|
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
|
||||||
{
|
{
|
||||||
pub(super) identifier: u64,
|
pub(super) identifier: u64,
|
||||||
pub(super) content: T,
|
pub(super) content: T,
|
||||||
@@ -46,7 +46,7 @@ where
|
|||||||
|
|
||||||
impl<T> TreeItem<T>
|
impl<T> TreeItem<T>
|
||||||
where
|
where
|
||||||
T: ToText + Clone + Default + Display + Hash,
|
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
|
||||||
{
|
{
|
||||||
/// Create a new `TreeItem` with children.
|
/// Create a new `TreeItem` with children.
|
||||||
///
|
///
|
||||||
|
|||||||
+1
-1
@@ -58,7 +58,7 @@ impl TreeState {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn flatten<'a, T>(&self, items: &'a [TreeItem<T>]) -> Vec<Flattened<'a, T>>
|
pub fn flatten<'a, T>(&self, items: &'a [TreeItem<T>]) -> Vec<Flattened<'a, T>>
|
||||||
where
|
where
|
||||||
T: ToText + Clone + Default + Display + Hash,
|
T: ToText + Clone + Default + Display + Hash + PartialEq + Eq,
|
||||||
{
|
{
|
||||||
flatten(&self.opened, items, &[])
|
flatten(&self.opened, items, &[])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user