Trait enso_flexer::prelude::PhantomConversions [−][src]
pub trait PhantomConversions { fn phantom_into<P>() -> P
where
Self: PhantomInto<P>, { ... } fn phantom_from<P>() -> Self
where
P: PhantomInto<Self>, { ... } }
Expand description
A utility for easy driving of type-level computations from value level. Often we’ve got some
type level relations, like a few singleton types, and for each such type we’ve got an associated
value. For example, we can define types Int
and Float
and associate with them
WebGlContext::Int
and WebGlContext::Float
constants encoded as GlEnum
. In order to convert
Int
or Float
to the GlEnum
we do not need the instance of the types, only the information
what type it was. So we can define:
ⓘ
impl From<PhantomData<Int>> for u32 { from(_:PhantomData<Int>>) { GlEnum(WebGlContext::Int) } }
And use it like:
ⓘ
let val = GlEnum::from(PhantomData::<Int>)
Using this utility we can always write the following code instead:
ⓘ
let val = GlEnum::phantom_from::<Int>()
Provided methods
fn phantom_into<P>() -> P where
Self: PhantomInto<P>,
[src]
Self: PhantomInto<P>,
fn phantom_from<P>() -> Self where
P: PhantomInto<Self>,
[src]
P: PhantomInto<Self>,