use core::any::{Any, TypeId};
fn type_of<U, V>() -> bool
where
U: core::any::Any + ?Sized,
V: core::any::Any + ?Sized,
{
core::any::TypeId::of::<U>() == core::any::TypeId::of::<V>()
}
pub trait TypeOf {
private!();
fn of<T: 'static>() -> bool;
}
pub trait IsType {
private!();
fn is<T>(&self) -> bool
where
T: 'static,
Self: 'static,
{
type_of::<Self, T>()
}
}
pub trait DType: 'static + IsType + TypeOf {
private!();
fn type_id(&self) -> TypeId {
Any::type_id(self)
}
fn type_name(&self) -> &'static str {
core::any::type_name::<Self>()
}
}
impl<T> DType for T
where
T: 'static,
{
seal!();
fn type_id(&self) -> TypeId {
Any::type_id(self)
}
fn type_name(&self) -> &'static str {
core::any::type_name::<Self>()
}
}
impl<T> TypeOf for T
where
T: 'static,
{
seal!();
fn of<U: 'static>() -> bool {
type_of::<T, U>()
}
}
impl<T> IsType for T
where
T: 'static,
{
seal!();
}