dungeon_cell/marker_traits/
size.rs

1use core::mem::MaybeUninit;
2use core::panic::{RefUnwindSafe, UnwindSafe};
3
4use super::sealed::Sealed;
5use crate::layout::Size;
6
7/// Marker only implemented for [`Size`].
8///
9/// This trait is [sealed](https://rust-lang.github.io/api-guidelines/future-proofing.html#sealed-traits-protect-against-downstream-implementations-c-sealed)
10/// and cannot be implemented by external types.
11pub trait IsSize:
12    Sealed
13    + Sized
14    + Copy
15    + Clone
16    + Sync
17    + Send
18    + Unpin
19    + RefUnwindSafe
20    + UnwindSafe
21    + 'static
22{
23    /// Type of the buffer with a size equal to [`Self::VALUE`].
24    ///
25    /// This type is always `[MaybeUninit<u8>; Self::VALUE]`.
26    type Buffer: Send
27        + Sync
28        + Unpin
29        + Clone
30        + Copy
31        + RefUnwindSafe
32        + UnwindSafe
33        + 'static;
34
35    /// An uninitialized instance of the associated [`Self::Buffer`].
36    const UNINIT_BUFFER: Self::Buffer;
37
38    /// Size of the associated [`Self::Buffer`].
39    const VALUE: usize;
40}
41
42impl<const N: usize> Sealed for Size<N> {}
43
44impl<const N: usize> IsSize for Size<N> {
45    type Buffer = [MaybeUninit<u8>; N];
46
47    const UNINIT_BUFFER: Self::Buffer = [MaybeUninit::<u8>::uninit(); N];
48
49    const VALUE: usize = N;
50}