ferroui_dynamic_data/cache/i_query.rs
1//! `IQuery<TObject, TKey>` and `ICache<TObject, TKey>` (`Cache/IQuery.cs`, `Cache/ICache.cs`).
2
3use super::ChangeSet;
4
5/// Read access to a keyed collection (`IQuery<TObject, TKey>`).
6pub trait IQuery<T, K> {
7 /// The number of items (`Count`).
8 fn count(&self) -> usize;
9 /// The items, in the order of enumeration (`Items`).
10 fn items(&self) -> Vec<T>;
11 /// The keys, in the order of enumeration (`Keys`).
12 fn keys(&self) -> Vec<K>;
13 /// The keys and items, in the order of enumeration (`KeyValues`).
14 fn key_values(&self) -> Vec<(K, T)>;
15 /// The item of `key` (`Lookup`).
16 fn lookup(&self, key: &K) -> Option<T>;
17}
18
19/// A keyed collection that can be edited (`ICache<TObject, TKey>`).
20pub trait ICache<T, K>: IQuery<T, K> {
21 /// Adds the item, or replaces the item of its key (`AddOrUpdate(TObject, TKey)`).
22 fn add_or_update(&mut self, item: T, key: K);
23 /// Removes every item (`Clear`).
24 fn clear(&mut self);
25 /// Applies a change set (`Clone(IChangeSet<TObject, TKey>)`).
26 fn clone_changes(&mut self, changes: &ChangeSet<T, K>);
27 /// Refreshes every item (`Refresh()`).
28 fn refresh_all(&mut self);
29 /// Refreshes the items of the keys (`Refresh(IEnumerable<TKey>)`).
30 fn refresh_keys(&mut self, keys: &mut dyn Iterator<Item = K>);
31 /// Refreshes the item of `key` (`Refresh(TKey)`).
32 fn refresh(&mut self, key: &K);
33 /// Removes the item of `key` (`Remove(TKey)`).
34 fn remove(&mut self, key: &K);
35 /// Removes the items of the keys (`Remove(IEnumerable<TKey>)`).
36 fn remove_keys(&mut self, keys: &mut dyn Iterator<Item = K>);
37}