Skip to main content

Reified

Struct Reified 

Source
pub struct Reified<'brand, T>
where T: ?Sized,
{ /* private fields */ }
Expand description

A branded token carrying a reified value.

The lifetime 'brand is existential, created fresh by each call to reify and prevented from escaping the callback by the higher-rank bound for<'brand>. This mirrors Haskell’s forall s. Reifies s a => Proxy s -> r scoping.

The PhantomData carrying fn(&'brand ()) -> &'brand () makes 'brand invariant, preventing the compiler from shrinking or growing it to unify with any other lifetime. This is what makes the brand unique.

§Examples

use reify_reflect_core::reify;

reify(&"hello", |token| {
    assert_eq!(*token.reflect(), "hello");
});

The token cannot escape:

use reify_reflect_core::reify;

let escaped = reify(&42, |token| {
    token // ERROR: borrowed data escapes the closure
});

Implementations§

Source§

impl<'brand, T> Reified<'brand, T>
where T: ?Sized,

Source

pub fn reflect(&self) -> &T

Reflect the reified value back to a runtime reference.

This is the Rust equivalent of Haskell’s reflect :: Reifies s a => proxy s -> a.

The branded lifetime ensures this reference cannot outlive the reify callback that created this token.

§Examples
use reify_reflect_core::reify;

let doubled = reify(&21i32, |token| {
    token.reflect() * 2
});
assert_eq!(doubled, 42);

Auto Trait Implementations§

§

impl<'brand, T> Freeze for Reified<'brand, T>
where T: ?Sized,

§

impl<'brand, T> RefUnwindSafe for Reified<'brand, T>
where T: RefUnwindSafe + ?Sized,

§

impl<'brand, T> Send for Reified<'brand, T>
where T: Sync + ?Sized,

§

impl<'brand, T> Sync for Reified<'brand, T>
where T: Sync + ?Sized,

§

impl<'brand, T> Unpin for Reified<'brand, T>
where T: ?Sized,

§

impl<'brand, T> UnsafeUnpin for Reified<'brand, T>
where T: ?Sized,

§

impl<'brand, T> UnwindSafe for Reified<'brand, T>
where T: RefUnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.