dirty_static 0.1.2

A container for an immutable value that allows sneaky reloading in debug mode (via UnsafeCell) while keeping the data safe and constant in release mode. This allows you to tweak data while testing an application, without having that data be mutable when the application is released. Intended for use with game assets, but suitable for any interactive application.
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented0 out of 0 items with examples
  • Size
  • Source code size: 17.35 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.39 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mistodon

dirty_static

Crates.io Docs.rs

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:

  1. force-dynamic which allows replacing the value of a DirtyStatic even in release mode.
  2. force-static which disallows replacing the value of a DirtyStatic even 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);