| Crates.io | single_thread_cell |
| lib.rs | single_thread_cell |
| version | 0.3.0 |
| created_at | 2025-01-22 16:44:15.827849+00 |
| updated_at | 2025-01-24 06:46:05.137752+00 |
| description | Create a cell that can only be accessed by a single thread. |
| homepage | |
| repository | https://github.com/KunoSayo/single_thread_cell |
| max_upload_size | |
| id | 1526835 |
| size | 26,907 |
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.
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);