unc_sdk/store/lazy_option/
impls.rs1use borsh::{BorshDeserialize, BorshSerialize};
2
3use super::LazyOption;
4
5impl<T> Drop for LazyOption<T>
6where
7 T: BorshSerialize,
8{
9 fn drop(&mut self) {
10 self.flush()
11 }
12}
13
14impl<T> core::ops::Deref for LazyOption<T>
15where
16 T: BorshSerialize + BorshDeserialize,
17{
18 type Target = Option<T>;
19
20 fn deref(&self) -> &Self::Target {
21 Self::get(self)
22 }
23}
24
25impl<T> core::ops::DerefMut for LazyOption<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> std::fmt::Debug for LazyOption<T>
35where
36 T: std::fmt::Debug + BorshSerialize + BorshDeserialize,
37{
38 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39 if cfg!(feature = "expensive-debug") {
40 self.get().fmt(f)
41 } else {
42 f.debug_struct("LazyOption")
43 .field("storage_key", &self.prefix)
44 .field("cache", &self.cache.get())
45 .finish()
46 }
47 }
48}