Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: something like INIT_SPACE #84

Open
mikemaccana opened this issue Jul 31, 2024 · 2 comments
Open

Feature request: something like INIT_SPACE #84

mikemaccana opened this issue Jul 31, 2024 · 2 comments

Comments

@mikemaccana
Copy link

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.

@mikemaccana mikemaccana changed the title Something like INIT_SPACE (or better yet, TOTAL_SPACE) Feature request: something like INIT_SPACE Jul 31, 2024
@lorisleiva
Copy link
Member

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
Copy link
Contributor

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(#)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants