Crates.io | staticslot |
lib.rs | staticslot |
version | 0.2.1 |
source | src |
created_at | 2017-07-15 19:24:22.691387 |
updated_at | 2017-12-21 17:02:31.60842 |
description | Atomic pointer type for holding static variables. |
homepage | https://github.com/sagebind/staticslot |
repository | https://github.com/sagebind/staticslot |
max_upload_size | |
id | 23519 |
size | 14,194 |
Atomic pointer type for holding static variables.
Add this to your Cargo.toml
file:
[dependencies]
staticslot = "0.2"
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.
MIT