#alignment #aligned #array #static

no-std aligned

Statically allocated arrays with guaranteed memory alignments

3 releases

0.1.2 Apr 25, 2018
0.1.1 May 30, 2017
0.1.0 May 30, 2017

#16 in Embedded development

Download history 101/week @ 2018-07-03 114/week @ 2018-07-10 103/week @ 2018-07-17 96/week @ 2018-07-24 98/week @ 2018-07-31 189/week @ 2018-08-07 166/week @ 2018-08-14 173/week @ 2018-08-21 442/week @ 2018-08-28 345/week @ 2018-09-04 447/week @ 2018-09-11 342/week @ 2018-09-18 506/week @ 2018-09-25

463 downloads per month
Used in 155 crates (5 directly)

MIT/Apache

8KB
167 lines

crates.io crates.io

aligned

Statically allocated arrays with guaranteed memory alignments

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:

Statically allocated arrays with guaranteed memory alignments

Examples

#![feature(const_fn)]

use std::mem;

use aligned::Aligned;

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

// Array aligned to a 4 byte boundary
static Y: Aligned<u32, [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<u64, _> = 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), 8);

No runtime deps