inscope

Crates.ioinscope
lib.rsinscope
version0.0.1
sourcesrc
created_at2023-05-12 11:36:49.452672
updated_at2023-05-12 11:36:49.452672
descriptionTrack and modify the scope of a variable
homepagehttps://github.com/panthios/rscore/tree/master/inscope
repositoryhttps://github.com/panthios/rscore
max_upload_size
id862910
size15,795
Carlos Kieliszewski (carlosskii)

documentation

https://docs.rs/inscope

README

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);
Commit count: 36

cargo fmt