lpc55_hal/traits/
aligned.rs

1/// Extract of relevant parts of `aligned` library,
2/// without its multi-generic-array dependency tree.
3use core::ops;
4
5pub trait Alignment {}
6
7/// 4-byte alignment
8#[repr(align(4))]
9pub struct A4;
10
11impl Alignment for A4 {}
12
13/// A newtype with alignment of at least `A` bytes
14#[repr(C)]
15pub struct Aligned<A, T>
16where
17    T: ?Sized,
18{
19    _alignment: [A; 0],
20    value: T,
21}
22
23/// Changes the alignment of `value` to be at least `A` bytes
24#[allow(non_snake_case)]
25pub const fn Aligned<A, T>(value: T) -> Aligned<A, T> {
26    Aligned {
27        _alignment: [],
28        value,
29    }
30}
31
32impl<A, T> ops::Deref for Aligned<A, T>
33where
34    A: Alignment,
35    T: ?Sized,
36{
37    type Target = T;
38
39    fn deref(&self) -> &T {
40        &self.value
41    }
42}
43
44impl<A, T> ops::DerefMut for Aligned<A, T>
45where
46    A: Alignment,
47    T: ?Sized,
48{
49    fn deref_mut(&mut self) -> &mut T {
50        &mut self.value
51    }
52}