1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use borsh::{BorshDeserialize, BorshSerialize};

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, BorshSerialize, BorshDeserialize)]
pub enum StorageOutcome {
    /// A value has been added to storage
    Inserted([u8; 32]),
    /// The existing value has been replaced with the new value
    Updated([u8; 32]),
    /// The value has been removed
    Zeroed([u8; 32]),
    /// The value does not exist
    NonExistentValue([u8; 32]),
    /// The value already exists in storage
    ValueExists([u8; 32]),
    /// The capacity of the storage has been reached
    CapacityExceeded,
    /// Storage filled with zero bytes array
    Vacant,
    /// Storage filled with non-zero bytes array
    Occupied,
}

#[cfg(feature = "heap_available")]
use core::fmt;
#[cfg(feature = "heap_available")]
impl fmt::Debug for StorageOutcome {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "StorageOutcome::{}",
            match self {
                StorageOutcome::Inserted(value) =>
                    format!("{}({})", "Inserted", hex::encode(value)),
                StorageOutcome::Updated(value) => format!("{}({})", "Updated", hex::encode(value)),
                StorageOutcome::Zeroed(value) => format!("{}({})", "Zeroed", hex::encode(value)),
                StorageOutcome::NonExistentValue(value) =>
                    format!("{}({})", "NonExistentValue", hex::encode(value)),
                StorageOutcome::ValueExists(value) =>
                    format!("{}({})", "ValueExists", hex::encode(value)),
                StorageOutcome::CapacityExceeded => format!("{}", "CapacityExceeded"),
                StorageOutcome::Vacant => format!("{}", "Vacant"),
                StorageOutcome::Occupied => format!("{}", "Occupied"),
            }
        )
    }
}