docs.rs failed to build global-lib-1.0.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Features
Globals by Name
- Any type — anything
Send + Sync + 'static: numbers, strings, collections,Arc<dyn Trait + Send + Sync> set,define,remove,contains—setreplaces a value of any type;defineis set-onceget,try_get,value,with— a shared handle, the same with the reason for a miss, a clone, or a closure over the value in placeedit— changes a value through a copy; concurrent edits never lose an update- Your own stores —
Globals::new()for an isolated set of values, or a fresh one per test, withnames,len,type_of, andclearon top
Typed Statics
static X: Global<T> = Global::new();— type checked at compile time, no name to hashset,define,take—setreturns the previous value;definegives your value back if one is already setget,value,with,is_set—withis the fastest read in the crate, about 5 nsedit— returnsfalsewithout calling the closure when nothing is set
Reads and Writes
- Lock-free, allocation-free reads — a hazard-pointer announcement, a borrow, a release
- Readers share nothing they write — aggregate read throughput grows with the number of threads
- Copy-on-write writes — serialized, never waiting for readers, and no lock is held while your closures run, so writing from inside a read or an edit cannot deadlock
- Handles stay valid — an
Arcfromgetkeeps its value alive after it is replaced or removed
Secrets
- Never printed —
Debuglists names and types; errors name the global and the types involved, never the value - Bounded error text — names echoed in errors are cut to 64 characters
Installation
[]
= "1.0"
Quick Start
use Global;
// By name: any Send + Sync + 'static type, in one process-wide store.
set;
define?; // set-once
let port: u16 = value.unwrap_or;
?;
let len = ;
// Typed: checked at compile time, no name lookup.
static MAX_CONNECTIONS: = new;
MAX_CONNECTIONS.set;
let max = MAX_CONNECTIONS.with.unwrap_or;
# Ok::
Wrong Types and Missing Values
use Error;
set;
// The quiet readers return None for a wrong type or a missing name.
assert_eq!;
// try_get and edit say why.
let err = .unwrap_err;
assert_eq!;
assert!;
A Store of Your Own
use LazyLock;
use Globals;
static PLUGINS: = new;
PLUGINS.set;
PLUGINS.set;
assert_eq!;
The free functions use one process-wide Globals, returned by global_lib::globals(). A Globals of your own keeps a group of values apart from it, and a Globals::new() per test keeps tests from seeing each other's values.
Documentation
- API reference — every public item, the semantics of each operation, and the cost model.
- Stability contract — what 1.x guarantees and what may still change.
- Performance — benchmark methodology and results.
- Developer guidelines — the engineering bar this project is built to.
- Release notes — what shipped, when, and why.
Contributing
Contributions are welcome under the project's dual license. Before opening a pull request, please make sure:
cargo fmt --all -- --checkpasses.cargo clippy --all-targets --all-features -- -D warningsis clean.cargo test --all-featurespasses.- New public items include documentation and at least one example.
- The API reference and CHANGELOG are updated alongside code changes.