use std::marker::PhantomData;
#[doc(hidden)]
pub struct TyCons<T>(PhantomData<T>);
impl<T> TyCons<T> {
pub fn new(_t: &T) -> TyCons<T> {
TyCons(PhantomData)
}
}
#[doc(hidden)]
pub trait TyConsExt: Sized {
type Cons;
fn ty_cons(self) -> Self::Cons {
panic!("should not be run, only for type resolution")
}
}
impl<T> TyCons<Option<&'_ T>> {
pub fn ty_cons(self) -> T {
panic!("should not be run, only for type resolution")
}
}
impl<T: Sized> TyConsExt for TyCons<&'_ T> {
type Cons = T;
}
impl TyConsExt for TyCons<&'_ str> {
type Cons = String;
}
impl<T> TyConsExt for TyCons<&'_ [T]> {
type Cons = Vec<T>;
}
impl<T> TyConsExt for TyCons<Option<T>> {
type Cons = T;
}
impl<T> TyConsExt for &'_ TyCons<T> {
type Cons = T;
}
#[test]
fn test_tycons_ext() {
if false {
let _: u64 = TyCons::new(&Some(5u64)).ty_cons();
let _: u64 = TyCons::new(&Some(&5u64)).ty_cons();
let _: u64 = TyCons::new(&&5u64).ty_cons();
let _: u64 = TyCons::new(&5u64).ty_cons();
}
}