#struct #alignment #size #ensure #macro #anchor #solana

macro aligned-sized

A macro which ensures the alignment and calculates the size of a struct

13 releases (2 stable)

1.1.0 Sep 20, 2024
0.6.0 Sep 8, 2024
0.3.0 Jul 23, 2024
0.1.0 Nov 1, 2023

#44 in #ensure

Download history 505/week @ 2024-08-24 86/week @ 2024-08-31 326/week @ 2024-09-07 209/week @ 2024-09-14 132/week @ 2024-09-21 68/week @ 2024-09-28 47/week @ 2024-10-05 77/week @ 2024-10-12 38/week @ 2024-10-19 36/week @ 2024-10-26 77/week @ 2024-11-02 162/week @ 2024-11-09 189/week @ 2024-11-16 136/week @ 2024-11-23 124/week @ 2024-11-30 270/week @ 2024-12-07

802 downloads per month
Used in 16 crates (9 directly)

Apache-2.0

10KB
169 lines

aligned-sized

A macro which ensures the alignment and calculates the size of a struct


lib.rs:

aligned-sized is a library providing the aligned_sized macro, which:

  • Calculates a size of the given struct and provides a LEN constant with that value.

Future plans:

  • Ensuring that the struct is aligned, adding padding fields when neccessary.

Motivation

Calculating the size of a struct is often a necessity when developing project in Rust, in particular:

This library provides a macro which automatically calculates the size, also taking in account factors which make a straightforward use of core::mem::size_of::<T> for the whole struct impossible (discriminants, vectors etc.).

Dependencies

~215–650KB
~16K SLoC