[][src]Trait drone_core::token::Token

pub unsafe trait Token: Sized + Send + 'static {
    unsafe fn take() -> Self;
}

A zero-sized affine type, at most one instance of which ever exists.

The above properties can't be expressed with Rust type-system, therefore the trait is marked unsafe, and it is the implementer responsibility to keep the following invariants:

  1. The type must not implement Clone.
  2. The type must be instantiated only inside Token::take method.
  3. The type must be zero-sized.

Required methods

unsafe fn take() -> Self

Creates the token instance.

Safety

At most one instance of the token must ever exist. This invariant can't be expressed with Rust type-system, therefore the method is marked unsafe, and it is the caller responsibility to keep the invariant.

It is recommended to call this method at the very beginning of the program and pass the instance further to the code.

Since the type is ZST, the method is no-op from the assembly perspective. Likewise passing the instance around doesn't consume the stack, and storing the instance inside other types doesn't consume the memory.

Loading content...

Implementors

Loading content...