#static #alignment #aligned #include-bytes

no-std align-data

Simply increase the alignment of any statics or include_bytes!

1 unstable release

0.1.0 Sep 6, 2020

#219 in No standard library

Download history 272/week @ 2021-09-28 340/week @ 2021-10-05 255/week @ 2021-10-12 419/week @ 2021-10-19 311/week @ 2021-10-26 334/week @ 2021-11-02 393/week @ 2021-11-09 293/week @ 2021-11-16 135/week @ 2021-11-23 280/week @ 2021-11-30 208/week @ 2021-12-07 212/week @ 2021-12-14 356/week @ 2021-12-21 286/week @ 2021-12-28 227/week @ 2022-01-04 240/week @ 2022-01-11

1,151 downloads per month
Used in 8 crates (6 directly)

MIT license

6KB

Align Data

MIT License crates.io docs.rs

Simply increase the alignment of any statics or include_bytes!.

Examples

When including raw data through include_bytes! it is often used to directly interpret as structured data however it does not align the included bytes according to the structured data's alignment.

This crate fixes this oversight:

use align_data::{include_aligned, Align4K};

static ALIGNED: &[u8] = include_aligned!(Align4K, "lib.rs");
assert_eq!(ALIGNED.as_ptr() as usize % 0x1000, 0);

The value of any constant expression can be forced to the given alignment:

use align_data::{aligned, Align16};

let five = aligned!(Align16, i32, 5);
assert_eq!(five as *const _ as usize % 0x10, 0);

License

Licensed under MIT License, see license.txt.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions.

No runtime deps