1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! Types of possible alignment type arguments for [`AlignedBytes`](`super::AlignedBytes`).
use cfg_if;
/// Trait for all alignment types that provides its size.
///
/// # Safety
/// The `size` returned must satisfy the following conditions:
/// - it is constant between calls, i.e. two calls to `size` for the same alignment *MUST* return the same value;
/// - the value returned is a power of two.
///
/// Violating any of these constraints will cause undefined behaviour when the alignment is used
/// for [`AlignedBytes`](`super::AlignedBytes`).
pub unsafe
/// Alignment to $2^N$. All acceptable alignments can be derived
/// from this alignment, for example 64-byte alignment is simply [`TwoTo<6>`].
///
/// # Examples
/// ```rust
/// use aligners::alignment::{self, Alignment};
///
/// assert_eq!(64, alignment::TwoTo::<6>::size());
/// ```
/// Alignment to 1 byte, so no special alignment – every slice is always one-byte-aligned.
///
/// # Examples
/// ```rust
/// use aligners::alignment::{self, Alignment};
///
/// assert_eq!(1, alignment::One::size());
/// ```
pub type One = ;
/// Alignment to 2 bytes, same as [`u16`]/[`i16`].
///
/// # Examples
/// ```rust
/// use aligners::alignment::{self, Alignment};
///
/// assert_eq!(2, alignment::Two::size());
/// ```
pub type Two = ;
/// Alignment to 4 bytes, same as [`u32`]/[`i32`].
///
/// # Examples
/// ```rust
/// use aligners::alignment::{self, Alignment};
///
/// assert_eq!(4, alignment::Four::size());
/// ```
pub type Four = ;
/// Alignment to 8 bytes, same as [`u64`]/[`i64`].
///
/// # Examples
/// ```rust
/// use aligners::alignment::{self, Alignment};
///
/// assert_eq!(8, alignment::Eight::size());
/// ```
pub type Eight = ;
// SAFETY:
// 2^N is a power of two (duh).
unsafe
cfg_if!
pub use *;
pub use *;