use core::marker::Unsize;
use crate::InplaceBox;
impl<T: ?Sized, const SIZE: usize> InplaceBox<T, SIZE> {
pub fn new<'a, U: Sized + Unsize<T> + 'a>(value: U) -> Self {
ConvertIntoInplaceBox::convert_into_inplace_box(value)
}
}
trait IsInPlaceBox<T: ?Sized, const SIZE: usize> {
fn move_out(self) -> InplaceBox<T, SIZE>;
}
impl<T: ?Sized, const SIZE: usize> IsInPlaceBox<T, SIZE>
for InplaceBox<T, SIZE>
{
#[inline]
fn move_out(self) -> InplaceBox<T, SIZE> {
self
}
}
trait ConvertIntoInplaceBox<'a, T, const SIZE: usize>
where T: ?Sized + 'a
{
fn convert_into_inplace_box(self) -> InplaceBox<T, SIZE>;
}
impl<'a, T, U, const SIZE: usize> ConvertIntoInplaceBox<'a, T, SIZE> for U
where
T: ?Sized + 'a,
U: Sized + Unsize<T> + 'a,
{
#[inline]
default fn convert_into_inplace_box(self) -> InplaceBox<T, SIZE> {
InplaceBox::new_impl(self)
}
}
impl<'a, T, U, const SIZE: usize> ConvertIntoInplaceBox<'a, T, SIZE> for U
where
T: ?Sized + 'a,
U: Sized + Unsize<T> + IsInPlaceBox<T, SIZE> + 'a,
{
#[inline]
fn convert_into_inplace_box(self) -> InplaceBox<T, SIZE> {
self.move_out()
}
}