#struct #size #ensure #alignment #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

#50 in #ensure

Download history 255/week @ 2024-11-15 136/week @ 2024-11-22 129/week @ 2024-11-29 235/week @ 2024-12-06 262/week @ 2024-12-13 344/week @ 2024-12-20 84/week @ 2024-12-27 68/week @ 2025-01-03 166/week @ 2025-01-10 144/week @ 2025-01-17 172/week @ 2025-01-24 361/week @ 2025-01-31 298/week @ 2025-02-07 292/week @ 2025-02-14 197/week @ 2025-02-21 264/week @ 2025-02-28

1,088 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

~200–640KB
~15K SLoC