use std_::mem;
#[cfg(feature = "std")]
use std::rc::Rc;
#[cfg(feature = "std")]
use std::sync::Arc;
use utils::transmute_ignore_size;
pub trait TypeIdentity {
type Type: ?Sized;
#[inline(always)]
fn into_type_val(self) -> Self::Type
where
Self: Sized,
Self::Type: Sized,
{
unsafe { transmute_ignore_size(self) }
}
#[inline(always)]
fn into_type_ref(&self) -> &Self::Type {
unsafe { mem::transmute_copy::<&Self, &Self::Type>(&self) }
}
#[inline(always)]
fn into_type_mut(&mut self) -> &mut Self::Type {
unsafe { mem::transmute_copy::<&mut Self, &mut Self::Type>(&self) }
}
#[cfg(feature = "std")]
#[inline(always)]
fn into_type_box(self: Box<Self>) -> Box<Self::Type> {
unsafe { transmute_ignore_size(self) }
}
#[cfg(feature = "std")]
#[inline(always)]
fn into_type_arc(this: Arc<Self>) -> Arc<Self::Type> {
unsafe { transmute_ignore_size(this) }
}
#[cfg(feature = "std")]
#[inline(always)]
fn into_type_rc(this: Rc<Self>) -> Rc<Self::Type> {
unsafe { transmute_ignore_size(this) }
}
#[inline(always)]
fn from_type_val(this: Self::Type) -> Self
where
Self: Sized,
Self::Type: Sized,
{
let this = mem::ManuallyDrop::new(this);
unsafe { mem::transmute_copy::<Self::Type, Self>(&*this) }
}
#[inline(always)]
fn from_type_ref(this: &Self::Type) -> &Self {
unsafe { mem::transmute_copy::<&Self::Type, &Self>(&this) }
}
#[inline(always)]
fn from_type_mut(this: &mut Self::Type) -> &mut Self {
unsafe { mem::transmute_copy::<&mut Self::Type, &mut Self>(&this) }
}
#[cfg(feature = "std")]
#[inline(always)]
fn from_type_box(this: Box<Self::Type>) -> Box<Self> {
unsafe { transmute_ignore_size(this) }
}
#[cfg(feature = "std")]
#[inline(always)]
fn from_type_arc(this: Arc<Self::Type>) -> Arc<Self> {
unsafe { transmute_ignore_size(this) }
}
#[cfg(feature = "std")]
#[inline(always)]
fn from_type_rc(this: Rc<Self::Type>) -> Rc<Self> {
unsafe { transmute_ignore_size(this) }
}
#[doc(hidden)]
#[allow(dead_code)]
fn _dummy_generic_method_preventing_trait_object<F>(self: &Self)
where
F: TypeIdentity<Type = Self>,
{
}
}
impl<T: ?Sized> TypeIdentity for T {
type Type = T;
}
pub type TIdentity<Type> = <Type as TypeIdentity>::Type;