Crate take_static

source ·
Expand description

This crate provides the take_static macro to create statics that provide mutable access only once:

use take_static::take_static;

take_static! {
    static NUMBER: usize = 5;
}

assert_eq!(NUMBER.take(), Some(&mut 5));
assert_eq!(NUMBER.take(), None);

The resulting statics are TakeStatic.

Macros

  • Declare a new static that provides mutable access—but only once.

Structs

  • A synchronization primitive which can be accessed only once.