3 releases (breaking)
0.3.0 | Jan 24, 2025 |
---|---|
0.2.0 | Jan 23, 2025 |
0.1.0 | Jan 22, 2025 |
#5 in #owner
354 downloads per month
11KB
213 lines
Introduction
This is a helper library to mark the cell as only being accessed by the owner thread.
If you access the cell from a different thread, the thread will be panicked.
Still in development, the API may change in the future.
Quick Start
use single_thread_cell::{SingleThreadCell, SingleThreadRefCell};
let cell = SingleThreadCell::new(0);
assert_eq!(cell.get(), 0);
cell.set(1);
assert_eq!(cell.get(), 1);
let ref_cell = SingleThreadRefCell::new(0);
assert_eq!(*ref_cell.borrow(), 0);
*ref_cell.borrow_mut() += 1;
assert_eq!(*ref_cell.borrow(), 1);
Related crates
lib.rs
:
This is a helper library to mark the cell as only being accessed by the owner thread.
If you access the cell from a different thread, the thread will be panicked.
The only exception is drop. The cell does not implement Send
if T
is not Send
.
So that the cell cannot be sent to another thread to drop.
It is obvious that if T
is Send
, it is safe to drop in the other thread.