solana-program / create-solana-program

pnpm create solana-program
Apache License 2.0
70 stars 9 forks source link

Feature request: something like INIT_SPACE #84

Open mikemaccana opened 1 month ago

mikemaccana commented 1 month ago

From the demo app:

pub const LEN: usize = 1 + 32 + 4;

In current Anchor we can avoid the magic numbers (and the readability or possible errors that go with magic numbers) with SomeSTRUCT::INIT_SPACE. It would be useful to have something similar in Shank.

lorisleiva commented 1 month ago

Hey @mikemaccana, AFAIK Shank doesn't have macros that generate helpers like this but if it did, how would it handle variable-length types such as Vec<PubKey>?

kevinrodriguez-io commented 3 weeks ago

I made something similar by extracting the proc macro out of anchor so it can run in non-anchor programs: https://github.com/kevinrodriguez-io/magic-space The only edge-case is when you have dynamic-spaced Vecs with constant realloc calls, or wherever you want to save some sol instead of using #[max_len(#)]