psy_macros/
lib.rs

1use proc_macro::TokenStream;
2
3mod mem;
4
5/// Use the "aligns" or "size" options to ensure memory and storage safety with state structs or enums.
6///
7/// *aligns*: Ensure struct can be included in a parent struct that is packed (e.g. anchor's zero_copy)
8///           without messing up the parent's alignment
9///           *Important*: This does not guarantee alignment within this struct!
10///
11/// *size: usize*: Enforces that the struct is a specific size
12///
13/// For example, decorate a struct with any of these attributes:
14/// #[assert_size(128, aligns)
15/// #[assert_size(128)
16/// #[assert_size(aligns)
17/// #[assert_size(aligns, 128)
18#[proc_macro_attribute]
19pub fn assert_size(args: TokenStream, input_struct: TokenStream) -> TokenStream {
20    mem::handler(args.into(), input_struct.into()).into()
21}