light_token_interface/state/extensions/
compressible.rs1use aligned_sized::aligned_sized;
2use light_compressible::compression_info::CompressionInfo;
3use light_zero_copy::{ZeroCopy, ZeroCopyMut};
4
5use crate::{AnchorDeserialize, AnchorSerialize};
6
7#[derive(
10 Debug,
11 Clone,
12 Hash,
13 Copy,
14 PartialEq,
15 Eq,
16 AnchorSerialize,
17 AnchorDeserialize,
18 ZeroCopy,
19 ZeroCopyMut,
20)]
21#[repr(C)]
22#[aligned_sized]
23pub struct CompressibleExtension {
24 pub decimals_option: u8,
26 pub decimals: u8,
28 pub compression_only: bool,
30 pub is_ata: u8,
33 pub info: CompressionInfo,
35}
36
37impl CompressibleExtension {
38 pub fn decimals(&self) -> Option<u8> {
40 if self.decimals_option == 1 {
41 Some(self.decimals)
42 } else {
43 None
44 }
45 }
46
47 pub fn set_decimals(&mut self, decimals: Option<u8>) {
49 match decimals {
50 Some(d) => {
51 self.decimals_option = 1;
52 self.decimals = d;
53 }
54 None => {
55 self.decimals_option = 0;
56 self.decimals = 0;
57 }
58 }
59 }
60}
61
62impl ZCompressibleExtension<'_> {
64 #[inline(always)]
66 pub fn decimals(&self) -> Option<u8> {
67 if self.decimals_option == 1 {
68 Some(self.decimals)
69 } else {
70 None
71 }
72 }
73}
74
75impl ZCompressibleExtensionMut<'_> {
77 #[inline(always)]
79 pub fn decimals(&self) -> Option<u8> {
80 if self.decimals_option == 1 {
81 Some(self.decimals)
82 } else {
83 None
84 }
85 }
86
87 #[inline(always)]
89 pub fn set_decimals(&mut self, decimals: Option<u8>) {
90 match decimals {
91 Some(d) => {
92 self.decimals_option = 1;
93 self.decimals = d;
94 }
95 None => {
96 self.decimals_option = 0;
97 self.decimals = 0;
98 }
99 }
100 }
101
102 #[inline(always)]
104 pub fn is_ata(&self) -> bool {
105 self.is_ata != 0
106 }
107}