3 releases
| new 0.1.2 | Oct 30, 2025 |
|---|---|
| 0.1.1 | Oct 20, 2019 |
| 0.1.0 | Oct 20, 2019 |
#275 in Configuration
10KB
133 lines
dirty_static
This crate provides a container for a value, DirtyStatic, which
allows mutation in debug mode (via UnsafeCell), but not in
release mode.
This allows you to tweak data while testing an application, without having that data be mutable when the application is released.
There are also two features available:
force-dynamicwhich allows replacing the value of aDirtyStaticeven in release mode.force-staticwhich disallows replacing the value of aDirtyStaticeven in debug mode.
Usage
// In debug mode
use dirty_static::DirtyStatic;
let c = DirtyStatic::new(100);
unsafe {
c.replace(200);
}
assert_eq!(*c, 200);
// In release mode
use dirty_static::DirtyStatic;
let c = DirtyStatic::new(100);
unsafe {
c.replace(200);
}
assert_eq!(*c, 100);