[][src]Type Definition phantasm::Invariant

type Invariant<T: ?Sized> = Invariant<T>;

Marker zst type that is invariant over T.

"Invariant" means that given F<_>, Super and Sub (where Sub is a subtype of Super), F<Sub> is not a subtype of F<Super> and vice versa - F<Super> is not a subtype of F<Sub>

Examples

// This struct is invariant over `T`
struct Test<T>(phantasm::Invariant<T> /* ... */);

let _: Test<i32> = Test(phantasm::Invariant);
let _ = Test(phantasm::Invariant::<i32>);
This example deliberately fails to compile
// `F<Super>` is **not** a subtype of `F<Sub>`
fn fail<'l>(arg: Invariant<&'l ()>) -> Invariant<&'static ()> {
    arg
}
This example deliberately fails to compile
// `F<Sub>` is **not** a subtype of `F<Super>`
fn fail<'l>(arg: Invariant<&'static ()>) -> Invariant<&'l ()> {
    arg
}

See also