unc_sdk/store/lazy/
impls.rs1use borsh::{BorshDeserialize, BorshSerialize};
2
3use super::Lazy;
4
5impl<T> Drop for Lazy<T>
6where
7 T: BorshSerialize,
8{
9 fn drop(&mut self) {
10 self.flush()
11 }
12}
13
14impl<T> core::ops::Deref for Lazy<T>
15where
16 T: BorshSerialize + BorshDeserialize,
17{
18 type Target = T;
19
20 fn deref(&self) -> &Self::Target {
21 Self::get(self)
22 }
23}
24
25impl<T> core::ops::DerefMut for Lazy<T>
26where
27 T: BorshSerialize + BorshDeserialize,
28{
29 fn deref_mut(&mut self) -> &mut Self::Target {
30 Self::get_mut(self)
31 }
32}
33
34impl<T> core::cmp::PartialEq for Lazy<T>
35where
36 T: PartialEq + BorshSerialize + BorshDeserialize,
37{
38 fn eq(&self, other: &Self) -> bool {
39 PartialEq::eq(self.get(), other.get())
40 }
41}
42
43impl<T> core::cmp::Eq for Lazy<T> where T: Eq + BorshSerialize + BorshDeserialize {}
44
45impl<T> core::cmp::PartialOrd for Lazy<T>
46where
47 T: PartialOrd + BorshSerialize + BorshDeserialize,
48{
49 fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
50 PartialOrd::partial_cmp(self.get(), other.get())
51 }
52 fn lt(&self, other: &Self) -> bool {
53 PartialOrd::lt(self.get(), other.get())
54 }
55 fn le(&self, other: &Self) -> bool {
56 PartialOrd::le(self.get(), other.get())
57 }
58 fn ge(&self, other: &Self) -> bool {
59 PartialOrd::ge(self.get(), other.get())
60 }
61 fn gt(&self, other: &Self) -> bool {
62 PartialOrd::gt(self.get(), other.get())
63 }
64}
65
66impl<T> core::cmp::Ord for Lazy<T>
67where
68 T: core::cmp::Ord + BorshSerialize + BorshDeserialize,
69{
70 fn cmp(&self, other: &Self) -> core::cmp::Ordering {
71 Ord::cmp(self.get(), other.get())
72 }
73}
74
75impl<T> core::convert::AsRef<T> for Lazy<T>
76where
77 T: BorshSerialize + BorshDeserialize,
78{
79 fn as_ref(&self) -> &T {
80 Self::get(self)
81 }
82}
83
84impl<T> core::convert::AsMut<T> for Lazy<T>
85where
86 T: BorshSerialize + BorshDeserialize,
87{
88 fn as_mut(&mut self) -> &mut T {
89 Self::get_mut(self)
90 }
91}
92
93impl<T> std::fmt::Debug for Lazy<T>
94where
95 T: std::fmt::Debug + BorshSerialize + BorshDeserialize,
96{
97 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
98 if cfg!(feature = "expensive-debug") {
99 self.get().fmt(f)
100 } else {
101 f.debug_struct("Lazy")
102 .field("storage_key", &self.storage_key)
103 .field("cache", &self.cache.get())
104 .finish()
105 }
106 }
107}