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
use crate::{Flat, FlatBase, FlatUnsized};
use core::mem::{align_of, size_of};
pub trait FlatSized: Flat + Sized {
const SIZE: usize;
}
impl<T: Flat + Sized> FlatBase for T {
const ALIGN: usize = align_of::<Self>();
const MIN_SIZE: usize = Self::SIZE;
fn size(&self) -> usize {
Self::SIZE
}
}
impl<T: Flat + Sized> FlatSized for T {
const SIZE: usize = size_of::<Self>();
}
impl<T: Flat + Sized> FlatUnsized for T {
type AlignAs = Self;
fn ptr_metadata(_: &[u8]) -> usize {
panic!("Getting ptr_metadata from sized type");
}
}