Skip to main content

ferroui_dynamic_data/cache/
key_value.rs

1//! `IKeyValue<TObject, TKey>` and `IKeyValueCollection<TObject, TKey>` (`Cache/IKeyValue.cs`,
2//! `Cache/IKeyValueCollection.cs`).
3
4use super::{KeyValueComparer, SortOptimisations, SortReason};
5
6/// A key and its item (`IKeyValue<TObject, TKey>`, with `IKey<TKey>`).
7pub trait IKeyValue<T, K> {
8    /// The key (`Key`).
9    fn key(&self) -> &K;
10    /// The item (`Value`).
11    fn value(&self) -> &T;
12}
13
14impl<T, K> IKeyValue<T, K> for (K, T) {
15    /// `KeyValuePair<TKey, TObject>.Key`.
16    fn key(&self) -> &K {
17        &self.0
18    }
19
20    /// `KeyValuePair<TKey, TObject>.Value`.
21    fn value(&self) -> &T {
22        &self.1
23    }
24}
25
26/// The sorted pairs of a key and an item of a sorted change set (`IKeyValueCollection<TObject,
27/// TKey>`, a read-only list of `KeyValuePair<TKey, TObject>`).
28pub trait IKeyValueCollection<T, K> {
29    /// The comparer of the pairs (`Comparer`).
30    fn comparer(&self) -> &KeyValueComparer<T, K>;
31    /// The optimisations of the sort (`Optimisations`).
32    fn optimisations(&self) -> SortOptimisations;
33    /// The reason of the sort (`SortReason`).
34    fn sort_reason(&self) -> SortReason;
35    /// The pairs, in order (the `IReadOnlyList`).
36    fn items(&self) -> &[(K, T)];
37}