inscope 0.0.1

Track and modify the scope of a variable
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented3 out of 4 items with examples
  • Size
  • Source code size: 15.7 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.49 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • carlosskii

inscope

This crate implements an Option-like type that can be used to represent values that are "in scope" or "out of scope".

This crate is currently unstable and is not recommended for use in production.

Why?

This crate was created to solve a problem that I encountered while working on various other Panthios utilities. I needed a way to represent values that were deletable in other threads, and the deletion should be reflected in the original thread. This could be solved with an Arc<Mutex<T>>, but that is overkill for this specific use case. Instead, the mutable-constant crate can be used to create a mutable Option that can be set to None from another thread.

Example

use inscope::Scope;

let scope = Scope::new(42);
assert_eq!(*scope, Some(42));

// This requires unsafe because defiant
// `Mc` mutations are unsafe
unsafe {
  scope.delete();
}

assert_eq!(*scope, None);