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
#![deny(
missing_docs,
unsafe_op_in_unsafe_fn,
clippy::as_conversions,
clippy::missing_safety_doc,
clippy::undocumented_unsafe_blocks,
rustdoc::broken_intra_doc_links,
rustdoc::missing_crate_level_docs
)]
#![no_std]
use ::core::alloc::Layout;
use ::mischief::{Frame, Metadata};
use ::ptr_meta::Pointee;
#[derive(Debug)]
#[repr(C, align(16))]
pub struct Align16<T: ?Sized>(pub T);
impl Align16<[u8]> {
pub fn frame(size: usize) -> Frame<Self> {
let metadata = size.checked_add(15).unwrap() & !15;
unsafe { Frame::new_unsized(metadata) }
}
}
impl Pointee for Align16<[u8]> {
type Metadata = <[u8] as Pointee>::Metadata;
}
unsafe impl Metadata<Align16<[u8]>> for usize {
unsafe fn pointee_layout(self) -> Layout {
unsafe { Layout::from_size_align_unchecked(self, 16) }
}
}