Struct rust_examples::brands::InvariantLifetime[][src]

pub struct InvariantLifetime<'id>(_);
Expand description

Lifetime wrapper which makes 'id invariant and has no size.

The invariance of 'id (resp. InvariantLifetime) comes from the underlying raw pointer type *mut &'id () - see the docs.

Zero size is achieved via the usage of opaque type PhantomData which only carries the type information until the compilation and then is “compiled away”.

Note that the invariance of 'id (resp. InvariantLifetime) means that one cannot change the brand ('id) of BrandedIndex or BrandedVec via subtyping.

Example: Size Test

use rust_examples::brands::InvariantLifetime;

assert_eq!(std::mem::size_of::<InvariantLifetime<'_>>(), std::mem::size_of::<()>());

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.