gmsol_utils/
init_space.rs1use anchor_lang::solana_program::pubkey::Pubkey;
2
3pub trait InitSpace {
5 const INIT_SPACE: usize;
7}
8
9impl InitSpace for bool {
10 const INIT_SPACE: usize = 1;
11}
12
13impl InitSpace for u8 {
14 const INIT_SPACE: usize = 1;
15}
16
17impl InitSpace for u64 {
18 const INIT_SPACE: usize = 8;
19}
20
21impl InitSpace for i64 {
22 const INIT_SPACE: usize = 8;
23}
24
25impl InitSpace for u128 {
26 const INIT_SPACE: usize = 16;
27}
28
29impl InitSpace for i128 {
30 const INIT_SPACE: usize = 16;
31}
32
33impl InitSpace for Pubkey {
34 const INIT_SPACE: usize = 32;
35}
36
37impl<T, const LEN: usize> InitSpace for [T; LEN]
38where
39 T: InitSpace,
40{
41 const INIT_SPACE: usize = T::INIT_SPACE * LEN;
42}
43
44impl<T> InitSpace for Option<T>
45where
46 T: InitSpace,
47{
48 const INIT_SPACE: usize = 1 + T::INIT_SPACE;
49}