#refcell #single-threaded #multi-threaded #abstracting #lock-api #alllow

refcell-lock-api

A single-threaded implementation of lock_api for RefCell, to alllow abstracting between single-threaded & multi-threaded code

1 unstable release

0.1.0 Jan 16, 2024

#381 in Concurrency

Apache-2.0 OR MIT

14KB
274 lines

cell-lock-api

An single-threaded implementation of lock_api using a RefCell.

This is primarily intended to allow abstracting over single-threaded and multi-threaded code.

Example

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])
}

Dependencies

~165KB