| Crates.io | lazymut |
| lib.rs | lazymut |
| version | 0.1.2 |
| created_at | 2025-08-02 06:36:29.791632+00 |
| updated_at | 2025-08-04 12:58:45.241037+00 |
| description | Similar to LazyCell, but use &mut self to get or initialization |
| homepage | |
| repository | https://github.com/A4-Tacks/lazymut-rs |
| max_upload_size | |
| id | 1778369 |
| size | 7,249 |
Similar to [std::cell::LazyCell], but use &mut self to get or initialization
Suitable for being wrapped in a Mutex
use lazymut::LazyMut;
use std::sync::Mutex;
static FOO: Mutex<LazyMut<Vec<i32>>> = Mutex::new(LazyMut::new(|| {
vec![1]
}));
let mut lock = FOO.lock().unwrap();
assert_eq!(lock.get(), &mut vec![1]);
lock.get().push(2);
assert_eq!(lock.get(), &mut vec![1, 2]);