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 of Exists are unusable as the compiler is unable to infer for<'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]

Creates an Exists object.

Trait Implementations

impl<F: for<'a> TyFnL<'a>> Clone for Exists<F> where
    <F as TyFnL<'a>>::Output: Clone
[src]

Returns a copy of the value. Read more

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]

impl<F: for<'a> TyFnL<'a>> Debug for Exists<F> where
    <F as TyFnL<'a>>::Output: Debug
[src]

Formats the value using the given formatter.