use std::hash::Hash;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TreeFilterConfig {
Disabled,
Enabled { auto_expand: bool },
}
impl TreeFilterConfig {
#[must_use]
pub const fn disabled() -> Self {
Self::Disabled
}
#[must_use]
pub const fn enabled() -> Self {
Self::Enabled { auto_expand: true }
}
#[must_use]
pub const fn enabled_manual_expand() -> Self {
Self::Enabled { auto_expand: false }
}
#[must_use]
pub const fn enabled_auto_expand(auto_expand: bool) -> Self {
Self::Enabled { auto_expand }
}
}
impl Default for TreeFilterConfig {
fn default() -> Self {
Self::disabled()
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct NoFilter;
impl<T: TreeModel> TreeFilter<T> for NoFilter {
#[inline]
fn is_match(&self, _model: &T, _id: T::Id) -> bool {
true
}
}
pub trait TreeModel {
type Id: Copy + Eq + Hash;
fn root(&self) -> Option<Self::Id>;
fn children(&self, id: Self::Id) -> &[Self::Id];
fn contains(&self, id: Self::Id) -> bool;
fn size_hint(&self) -> usize {
0
}
}
pub trait TreeFilter<T: TreeModel> {
fn is_match(&self, model: &T, id: T::Id) -> bool;
}
impl<T, F> TreeFilter<T> for F
where
T: TreeModel,
F: Fn(&T, T::Id) -> bool,
{
#[inline]
fn is_match(&self, model: &T, id: T::Id) -> bool {
self(model, id)
}
}