use core::alloc::Layout;
use core::marker::PhantomData;
#[derive(Default, Debug, Copy, Clone)]
pub struct Single<T> {
_phantom: PhantomData<T>,
}
impl<T> Single<T> {
#[inline]
pub fn new() -> Self {
Self {
_phantom: PhantomData,
}
}
}
impl<T> From<Single<T>> for Option<Layout> {
#[inline]
fn from(_: Single<T>) -> Option<Layout> {
Some(Layout::new::<T>())
}
}
#[derive(Debug, Copy, Clone)]
pub struct Array<T> {
len: usize,
_phantom: PhantomData<T>,
}
impl<T> Array<T> {
#[inline]
pub fn from_len(len: usize) -> Self {
Self {
len,
_phantom: PhantomData,
}
}
#[inline]
pub fn len(&self) -> usize {
self.len
}
}
impl<T> From<Array<T>> for Option<Layout> {
#[inline]
fn from(array: Array<T>) -> Option<Layout> {
Layout::array::<T>(array.len).ok()
}
}