ghost_cell/lib.rs
1//! This library provides an implementation of `GhostCell` and its `GhostToken` as per
2//! <https://plv.mpi-sws.org/rustbelt/ghostcell/> as well as some extensions.
3//!
4//! # Safety
5//!
6//! The actual implementation of `GhostCell` is found at <https://gitlab.mpi-sws.org/FP/ghostcell/-/tree/master/ghostcell>
7//! and has been proven safe. I have carefully checked that this implementation faithfully reproduces the safety
8//! guarantees.
9//!
10//! Extensions to `GhostCell`, such as `GhostCursor`, are not proven, neither at the design nor implementation level.
11//! As such, they are only available if the appropriate Cargo features are enabled.
12//!
13//! # Example
14//!
15//! A simple self-contained example:
16//!
17//! ```rust
18//! use ghost_cell::{GhostToken, GhostCell};
19//!
20//! let n = 42;
21//!
22//! let value = GhostToken::new(|mut token| {
23//! let cell = GhostCell::new(42);
24//!
25//! let vec: Vec<_> = (0..n).map(|_| &cell).collect();
26//!
27//! *vec[n / 2].borrow_mut(&mut token) = 33;
28//!
29//! *cell.borrow(&token)
30//! });
31//!
32//! assert_eq!(33, value);
33//! ```
34
35// Generic features.
36#![cfg_attr(not(test), no_std)]
37// Lints.
38#![deny(missing_docs)]
39
40pub mod ghost_cell;
41
42pub use self::ghost_cell::{GhostCell, GhostToken};
43
44pub mod ghost_borrow;
45
46pub use self::ghost_borrow::GhostBorrow;
47
48#[cfg(feature = "experimental-multiple-mutable-borrows")]
49pub mod ghost_borrow_mut;
50
51#[cfg(feature = "experimental-multiple-mutable-borrows")]
52pub use self::ghost_borrow_mut::{GhostAliasingError, GhostBorrowMut};
53
54#[cfg(feature = "experimental-ghost-cursor")]
55pub mod ghost_cursor;
56
57#[cfg(feature = "experimental-ghost-cursor")]
58pub use self::ghost_cursor::GhostCursor;