patternfly_yew/components/table/model/
mod.rs1mod hook;
2mod memoized;
3mod state;
4mod table;
5
6pub use hook::*;
7pub use memoized::*;
8pub use state::*;
9use std::fmt::Debug;
10pub use table::*;
11
12use super::TableEntryRenderer;
13use std::rc::Rc;
14use yew::virtual_dom::Key;
15
16pub trait TableModel<C>
18where
19 C: Clone + Eq + 'static,
20{
21 type Iterator<'i>: Iterator<Item = TableModelEntry<'i, Self::Item, Self::Key, C>>
22 where
23 Self: 'i;
24 type Item: TableEntryRenderer<C> + Clone + 'static;
25 type Key: Into<Key> + Clone + Debug + Eq + 'static;
26
27 fn len(&self) -> usize;
29
30 fn is_empty(&self) -> bool {
32 self.len() == 0
33 }
34
35 fn iter(&self) -> Self::Iterator<'_>;
37}
38
39impl<C, M> TableModel<C> for Rc<M>
40where
41 C: Clone + Eq + 'static,
42 M: TableModel<C> + 'static,
43{
44 type Iterator<'i> = M::Iterator<'i>;
45 type Item = M::Item;
46 type Key = M::Key;
47
48 fn len(&self) -> usize {
49 self.as_ref().len()
50 }
51
52 fn is_empty(&self) -> bool {
53 self.as_ref().is_empty()
54 }
55
56 fn iter(&self) -> Self::Iterator<'_> {
57 self.as_ref().iter()
58 }
59}
60
61pub trait TableDataModel<C>
62where
63 C: Clone + Eq + 'static,
64{
65 type Iterator<'i>: Iterator<Item = (Self::Key, &'i Self::Item)>
66 where
67 Self: 'i;
68 type Item: TableEntryRenderer<C> + Clone + 'static;
69 type Key: Into<Key> + Clone + Debug + Eq + 'static;
70
71 fn len(&self) -> usize;
73
74 fn is_empty(&self) -> bool {
76 self.len() == 0
77 }
78
79 fn contains(&self, key: &Self::Key) -> bool;
81
82 fn iter(&self) -> Self::Iterator<'_>;
84}
85
86impl<C, M> TableDataModel<C> for Rc<M>
87where
88 C: Clone + Eq + 'static,
89 M: TableDataModel<C> + 'static,
90{
91 type Iterator<'i> = M::Iterator<'i>;
92 type Item = M::Item;
93 type Key = M::Key;
94
95 fn len(&self) -> usize {
96 self.as_ref().len()
97 }
98
99 fn is_empty(&self) -> bool {
100 self.as_ref().is_empty()
101 }
102
103 fn contains(&self, key: &Self::Key) -> bool {
104 self.as_ref().contains(key)
105 }
106
107 fn iter(&self) -> Self::Iterator<'_> {
108 self.as_ref().iter()
109 }
110}
111
112pub struct TableModelEntry<'t, T, K, C>
113where
114 K: Into<Key>,
115 C: Clone + Eq,
116{
117 pub value: &'t T,
118 pub key: K,
119 pub expansion: Option<ExpansionState<C>>,
120}