use core::marker::PhantomData;
use erased::Erased;
use crate::lt_list::Subset;
use crate::tag::{TagTypeId, WithLt};
use crate::LtList;
mod erased;
pub struct MutErasedWide<'u, L: LtList> {
_lt: PhantomData<&'u mut dyn core::any::Any>,
borrow: Erased<{ core::mem::size_of::<&mut dyn core::any::Any>() }>,
tag_type_id: TagTypeId<L>,
}
impl<'u, L: LtList> MutErasedWide<'u, L> {
pub fn new<T: ?Sized + WithLt<TL> + 'static, TL: LtList + Subset<L>>(
borrow: &'u mut T::Reified,
) -> Self {
Self {
_lt: PhantomData,
borrow: Erased::new::<&'u mut T::Reified>(borrow),
tag_type_id: TagTypeId::<L>::of::<T, TL>(),
}
}
pub fn downcast<T: ?Sized + WithLt<TL> + 'static, TL: LtList + Subset<L>>(
self,
) -> Result<&'u mut T::Reified, Self> {
if self.tag_type_id.is_same(&TagTypeId::<L>::of::<T, TL>()) {
Ok(unsafe { self.borrow.into_inner::<&'u mut T::Reified>() })
} else {
Err(self)
}
}
}