13 releases

0.4.2 Mar 24, 2024
0.4.1 May 13, 2022
0.4.0 Jul 24, 2021
0.3.4 Jul 31, 2020
0.1.1 May 30, 2017

#382 in Embedded development

Download history 12324/week @ 2023-12-23 12408/week @ 2023-12-30 17106/week @ 2024-01-06 18248/week @ 2024-01-13 15255/week @ 2024-01-20 15687/week @ 2024-01-27 14019/week @ 2024-02-03 15378/week @ 2024-02-10 14524/week @ 2024-02-17 14023/week @ 2024-02-24 13058/week @ 2024-03-02 14046/week @ 2024-03-09 13041/week @ 2024-03-16 14520/week @ 2024-03-23 14935/week @ 2024-03-30 10060/week @ 2024-04-06

54,314 downloads per month
Used in 692 crates (11 directly)

MIT/Apache

11KB
288 lines

crates.io crates.io

aligned

A newtype with alignment of at least A bytes

License

Licensed under either of

at your option.

Contribution

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


lib.rs:

A newtype with alignment of at least A bytes

Examples

use std::mem;

use aligned::{Aligned, A2, A4, A16};

// Array aligned to a 2 byte boundary
static X: Aligned<A2, [u8; 3]> = Aligned([0; 3]);

// Array aligned to a 4 byte boundary
static Y: Aligned<A4, [u8; 3]> = Aligned([0; 3]);

// Unaligned array
static Z: [u8; 3] = [0; 3];

// You can allocate the aligned arrays on the stack too
let w: Aligned<A16, _> = Aligned([0u8; 3]);

assert_eq!(mem::align_of_val(&X), 2);
assert_eq!(mem::align_of_val(&Y), 4);
assert_eq!(mem::align_of_val(&Z), 1);
assert_eq!(mem::align_of_val(&w), 16);

Dependencies

~18KB