Crates.io | singleton-cell |
lib.rs | singleton-cell |
version | 0.3.1 |
source | src |
created_at | 2021-07-18 01:55:49.706331 |
updated_at | 2022-05-02 04:00:33.801564 |
description | A more powerful Ghost Cell allowing the use of any singleton as the key |
homepage | |
repository | https://gitlab.com/jcarr0/scell |
max_upload_size | |
id | 424235 |
size | 15,809 |
This library provides a safe, zero-overhead interface for guarding access
to shared data via access to another singleton token. It is an extension of GhostCell to allow more general singletons besides branded tokens,
enabling data to be 'static
This library also provides two singleton implementations by itself:
with_token
new_singleton
'static
and thus stored in 'static
data-structures.with_token
method to emulate GhostCell.from_mut
and similar interfaces: they are structural like Cell and GhostCell.See the examples directory for some code samples
new_singleton(pub Lock);
pub fn main() {
let mut lock1 = Lock::new().expect("Called main twice");
let cell1 = SCell::new(0);
let cell2 = &cell1;
cell1.borrow_mut(&mut lock1) += 1;
assert_eq!(1, *cell2.borrow(&lock1));
}