Crates.io | refcell-lock-api |
lib.rs | refcell-lock-api |
version | 0.1.0 |
source | src |
created_at | 2024-01-16 16:18:44.785166 |
updated_at | 2024-01-16 16:18:44.785166 |
description | A single-threaded implementation of lock_api for RefCell, to alllow abstracting between single-threaded & multi-threaded code |
homepage | |
repository | https://github.com/Techcable/refcell-lock-api |
max_upload_size | |
id | 1101771 |
size | 26,107 |
An single-threaded implementation of lock_api using a RefCell.
This is primarily intended to allow abstracting over single-threaded and multi-threaded code.
use cell_lock_api::CellRwLock;
fn main() {
let lock = CellRwLock::new(vec![7i32]);
{
let guard = lock.read();
assert_eq!(*guard, vec![7]);
}
{
let mut guard = lock.write();
guard.push(18);
guard.push(19);
}
assert_eq!(lock.into_inner(), vec![7, 18, 19])
}