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,
impl<'brand, T> Reified<'brand, T>where
T: ?Sized,
Sourcepub fn reflect(&self) -> &T
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>
impl<'brand, T> Sync for Reified<'brand, T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more