ferroui_dynamic_data/cache/
change_set_with_context.rs1use super::{Change, ChangeSet, IChangeSet};
5use std::fmt;
6use std::ops::Deref;
7
8pub struct ChangeSetWithContext<T, K, X> {
17 changes: ChangeSet<T, K>,
18 context: X,
19}
20
21impl<T, K, X: Clone> Clone for ChangeSetWithContext<T, K, X> {
22 fn clone(&self) -> Self {
23 Self { changes: self.changes.clone(), context: self.context.clone() }
24 }
25}
26
27impl<T, K, X> ChangeSetWithContext<T, K, X> {
28 pub fn new(collection: ChangeSet<T, K>, context: X) -> Self {
30 Self { changes: collection, context }
31 }
32
33 pub fn empty(context: X) -> Self {
35 Self::new(ChangeSet::empty(), context)
36 }
37
38 pub fn context(&self) -> &X {
40 &self.context
41 }
42
43 pub fn changes(&self) -> &ChangeSet<T, K> {
45 &self.changes
46 }
47}
48
49impl<T, K, X> Deref for ChangeSetWithContext<T, K, X> {
50 type Target = ChangeSet<T, K>;
51
52 fn deref(&self) -> &Self::Target {
53 &self.changes
54 }
55}
56
57impl<'a, T, K, X> IntoIterator for &'a ChangeSetWithContext<T, K, X> {
58 type Item = &'a Change<T, K>;
59 type IntoIter = std::slice::Iter<'a, Change<T, K>>;
60
61 fn into_iter(self) -> Self::IntoIter {
62 self.changes.changes().iter()
63 }
64}
65
66impl<T: 'static, K: 'static, X: Clone + 'static> IChangeSet<T, K> for ChangeSetWithContext<T, K, X> {
67 fn change_set(&self) -> &ChangeSet<T, K> {
68 &self.changes
69 }
70}
71
72impl<T: fmt::Debug, K: fmt::Debug, X: fmt::Debug> fmt::Debug for ChangeSetWithContext<T, K, X> {
73 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
74 f.debug_struct("ChangeSetWithContext").field("changes", &self.changes).field("context", &self.context).finish()
75 }
76}