#alignment #static #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

#190 in No standard library

Download history 821/week @ 2024-07-22 527/week @ 2024-07-29 722/week @ 2024-08-05 797/week @ 2024-08-12 777/week @ 2024-08-19 845/week @ 2024-08-26 574/week @ 2024-09-02 678/week @ 2024-09-09 701/week @ 2024-09-16 754/week @ 2024-09-23 777/week @ 2024-09-30 759/week @ 2024-10-07 581/week @ 2024-10-14 510/week @ 2024-10-21 589/week @ 2024-10-28 456/week @ 2024-11-04

2,193 downloads per month
Used in 11 crates (7 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