libutils-cage 0.0.6

A thread-safe static mutable wrapper
Documentation

Cage

Cage<Type> is a reader-writer wrapper lock with a simple and safe API.

Usage

use libutils::cage::Cage;

static MUTABLE: Cage<u8> = Cage::default();

MUTABLE.write(|variable| *variable = 1); // get a mutable reference

let x = MUTABLE.get(); // copy

The Cage type offers a wrapper around RwLock from the standard library with a simplified API.

Performance

This type's performance largely dependent on the RwLock implementation.

When to use it

The type is useful in two situations:

  • Static mutable variables: synchronizes access
  • Interior mutability: enforces borrow checker rules at compile-time