stack_memdb/
stack_usize.rs1use borsh::{BorshDeserialize, BorshSerialize};
2use core::fmt;
3
4#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, BorshDeserialize, BorshSerialize)]
5pub enum StackUsize {
6 U0 = 0x00,
7 U2 = 0x02,
8 U3 = 0x03,
9 U4 = 0x04,
10}
11
12impl From<usize> for StackUsize {
13 fn from(value: usize) -> Self {
14 match value {
15 0x02 => StackUsize::U2,
16 0x03 => StackUsize::U3,
17 0x04 => StackUsize::U4,
18 _ => StackUsize::U0,
19 }
20 }
21}
22
23impl Default for StackUsize {
24 fn default() -> Self {
25 StackUsize::U2
26 }
27}
28
29impl fmt::Debug for StackUsize {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 write!(
32 f,
33 "{}",
34 match self {
35 StackUsize::U0 => "StackUsize::U0",
36 StackUsize::U2 => "StackUsize::U2",
37 StackUsize::U3 => "StackUsize::U3",
38 StackUsize::U4 => "StackUsize::U4",
39 }
40 )
41 }
42}
43
44pub const fn init_storage_stack(bar: &StackUsize) -> usize {
45 match bar {
46 StackUsize::U2 => 2,
47 StackUsize::U3 => 3,
48 StackUsize::U4 => 4,
49 _ => 0,
50 }
51}