fuel_core_chain_config/config/
table_entry.rs

1use fuel_core_storage::Mappable;
2
3#[derive(serde::Serialize, serde::Deserialize)]
4pub struct TableEntry<T>
5where
6    T: Mappable,
7{
8    pub key: T::OwnedKey,
9    pub value: T::OwnedValue,
10}
11
12impl<T> Clone for TableEntry<T>
13where
14    T: Mappable,
15{
16    fn clone(&self) -> Self {
17        Self {
18            key: self.key.clone(),
19            value: self.value.clone(),
20        }
21    }
22}
23
24impl<T> Copy for TableEntry<T>
25where
26    T: Mappable,
27    T::OwnedKey: Copy,
28    T::OwnedValue: Copy,
29{
30}
31
32impl<T> std::fmt::Debug for TableEntry<T>
33where
34    T: Mappable,
35    T::OwnedKey: std::fmt::Debug,
36    T::OwnedValue: std::fmt::Debug,
37{
38    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> core::fmt::Result {
39        f.debug_struct("TableEntry")
40            .field("key", &self.key)
41            .field("value", &self.value)
42            .finish()
43    }
44}
45
46impl<T> PartialEq for TableEntry<T>
47where
48    T: Mappable,
49    T::OwnedKey: PartialEq,
50    T::OwnedValue: PartialEq,
51{
52    fn eq(&self, other: &Self) -> bool {
53        self.key == other.key && self.value == other.value
54    }
55}
56
57impl<T> Eq for TableEntry<T>
58where
59    T: Mappable,
60    T::OwnedKey: Eq,
61    T::OwnedValue: Eq,
62{
63}
64
65impl<T> PartialOrd for TableEntry<T>
66where
67    T: Mappable,
68    T::OwnedKey: PartialOrd,
69    T::OwnedValue: PartialOrd,
70{
71    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
72        match self.key.partial_cmp(&other.key) {
73            Some(std::cmp::Ordering::Equal) => self.value.partial_cmp(&other.value),
74            other => other,
75        }
76    }
77}
78
79impl<T> Ord for TableEntry<T>
80where
81    T: Mappable,
82    T::OwnedKey: Ord,
83    T::OwnedValue: Ord,
84{
85    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
86        match self.key.cmp(&other.key) {
87            std::cmp::Ordering::Equal => self.value.cmp(&other.value),
88            other => other,
89        }
90    }
91}