#thread #static-cell #single-thread-cell

single_thread_cell

Create a cell that can only be accessed by a single thread

3 releases (breaking)

0.3.0 Jan 24, 2025
0.2.0 Jan 23, 2025
0.1.0 Jan 22, 2025

#445 in Concurrency

Apache-2.0

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);

No runtime deps