Struct imprint::Exists
[−]
[src]
pub struct Exists<F: for<'a> TyFnL<'a>>(_);
An object with an existentially quantified lifetime.
The main purpose of this type is to allow fictitious lifetimes to be
"forgotten" safely. Even after forgetting the lifetime, it is still
possible to do useful operations on the object within. This can be
especially useful in conjunction with Val
.
Known bugs:
- Use of
Exists::with
can cause internal compiler errors. See rust#39779. - The trait (
Clone
,Copy
,Debug
, etc.) implementations ofExists
are unusable as the compiler is unable to inferfor<'a> <F as TyFnL<'a>>::Output: SomeTrait
. Seems related to rust#30472.
Example
This example is for demonstration only: since exists<'x> Val<'x, T>
is
completely isomorphic to T
, there's no point in ever using ExistsVal
!
use imprint::{Exists, IntoInner, Val, ValF, imprint}; pub struct ExistsVal<T>(Exists<ValF<T>>); impl<T> ExistsVal<T> { // existential constructor (introduction rule) pub fn new<'x>(value: Val<'x, T>) -> Self { ExistsVal(Exists::new(value)) } // existential projector (elimination rule) pub fn with<F, R>(self, callback: F) -> R where F: for<'x> FnOnce(Val<'x, T>) -> R { self.0.with(|v| callback(v)) } // ExistsVal<T> -> T pub fn into_inner<'x>(self) -> T { self.with(|v| v.into_inner()) } } // T -> ExistsVal<T> impl<T> From<T> for ExistsVal<T> { fn from(t: T) -> Self { imprint(t, |v| ExistsVal::new(v)) } }
Methods
impl<F: for<'a> TyFnL<'a>> Exists<F>
[src]
fn new<'a>(value: <F as TyFnL<'a>>::Output) -> Exists<F>
Creates an Exists
object.
fn with<U, R>(self, callback: U) -> R where
U: for<'a> FnOnce(<F as TyFnL<'a>>::Output) -> R,
U: for<'a> FnOnce(<F as TyFnL<'a>>::Output) -> R,
fn with_ref<'b, U, R>(&'b self, callback: U) -> R where
U: for<'a> FnOnce(&'b <F as TyFnL<'a>>::Output) -> R,
U: for<'a> FnOnce(&'b <F as TyFnL<'a>>::Output) -> R,
fn with_ref_mut<'b, U, R>(&'b mut self, callback: U) -> R where
U: for<'a> FnOnce(&'b mut <F as TyFnL<'a>>::Output) -> R,
U: for<'a> FnOnce(&'b mut <F as TyFnL<'a>>::Output) -> R,
Trait Implementations
impl<F: for<'a> TyFnL<'a>> Clone for Exists<F> where
<F as TyFnL<'a>>::Output: Clone,
[src]
<F as TyFnL<'a>>::Output: Clone,
fn clone(&self) -> Self
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<F: for<'a> TyFnL<'a>> Copy for Exists<F> where
<F as TyFnL<'a>>::Output: Copy,
[src]
<F as TyFnL<'a>>::Output: Copy,
impl<F: for<'a> TyFnL<'a>> Debug for Exists<F> where
<F as TyFnL<'a>>::Output: Debug,
[src]
<F as TyFnL<'a>>::Output: Debug,