| Crates.io | alopt |
| lib.rs | alopt |
| version | 1.0.0 |
| created_at | 2025-03-13 23:41:10.648677+00 |
| updated_at | 2025-03-15 05:38:20.649033+00 |
| description | a Rust crate providing efficient synchronization primitives that integrate Option into their design. |
| homepage | |
| repository | https://github.com/nucleus-labs/alopt |
| max_upload_size | |
| id | 1591631 |
| size | 88,494 |
alopt (Arc-Lock-Option) is a Rust crate providing efficient synchronization primitives that integrate
Option into their design.
Worl<T>: A replacement for RwLock<Option<T>>, integrating optional storage directly into a
lockable structure.Wom<T>: A replacement for Mutex<Option<T>>, integrating optional storage directly into a
lockable structure.Worl<T>:
use std::sync::Arc;
use std::thread;
use alopt::thread::Worl;
let worl = Arc::new(Worl::new(42));
let worl_clone = worl.clone();
let handle = thread::spawn(move || {
let mut guard = worl_clone.write().unwrap();
*guard = 100;
});
handle.join().unwrap();
assert_eq!(*worl.read().unwrap(), 100);
Wom<T>:
use std::sync::Arc;
use std::thread;
use alopt::thread::Wom;
let wom = Arc::new(Wom::new(0));
let wom_clone = wom.clone();
*wom.get_mut().unwrap() = 42;
let handle = thread::spawn(move || {
let mut guard = wom_clone.lock().unwrap();
*guard += 100;
});
handle.join().unwrap();
assert_eq!(*worl.read().unwrap(), 142);
alopt?Option Handling: Eliminates the need for RwLock<Option<T>> or Mutex<Option<T>>,
reducing unnecessary layers of indirection.Add alopt to your Cargo.toml:
[dependencies]
alopt = "0.1"
alopt is licensed under the MIT License.