#static #global #singleton

yanked staticslot

Atomic pointer type for holding static variables

Uses old Rust 2015

0.2.1 Dec 21, 2017
0.2.0 Jul 16, 2017
0.1.0 Jul 15, 2017

#44 in #singleton

MIT license

13KB
122 lines

staticslot

Atomic pointer type for holding static variables.

Shippable Crates.io Documentation License

Documentation

Installation

Add this to your Cargo.toml file:

[dependencies]
staticslot = "0.2"

Overview

This crate provides a simple type, StaticSlot<T>, which is designed to make it easy to use static variables without much boilerplate or overhead. Usually you do not need any type of global variable, as it can introduce a number of problems into your code with bugs and testability. That being said, in certain applications a global variable is the most practical or efficient solution. This crate is targeted toward these uses.

A static slot is just a nullable pointer to some heap-allocated value with some extra features. We can declare one like this:

static GLOBAL_STRINGS: StaticSlot<Vec<String>> = StaticSlot::NULL;

Then we can get() and set() the value throughout our program. In addition, a number of convenience methods are also provided. See the documentation for details about semantics and safety.

License

MIT

No runtime deps