token_cell/lib.rs
1#![deny(
2 clippy::missing_panics_doc,
3 clippy::missing_const_for_fn,
4 clippy::missing_safety_doc,
5 clippy::missing_errors_doc,
6 missing_docs
7)]
8
9//! This library provides an alternative to [`ghost-cell`](https://crates.io/crates/ghost-cell) which uses concrete types instead of lifetimes for branding.
10//!
11//! This allows a more convenient usage, where cells and tokens can be constructed independently, with the same compile-time guarantees as [`ghost-cell`](https://crates.io/crates/ghost-cell). The trade-off for this arguably more convenient usage and arguably easier to understand branding method is that tokens, while zero-sized if made correctly, must be guaranteed to be constructable only if no other instance exists.
12#![cfg_attr(not(feature = "std"), no_std)]
13pub use paste::paste;
14#[cfg(feature = "std")]
15mod std {
16 use crate::macros::SingletonUnavailable;
17 use crate::runtime_token_support::{IdMismatch, Identifier};
18 extern crate std;
19 impl<T: Identifier> std::error::Error for IdMismatch<T> {}
20 impl std::error::Error for SingletonUnavailable {}
21}
22/// The basis for using `token_cell`
23pub mod prelude {
24 pub use crate::core::{
25 TokenCell, TokenCellTrait, TokenTrait, UnsafeTokenCellTrait, UnscopedToken,
26 };
27}
28pub use crate::macros::token;
29/// The core aspects of `token_cell`
30pub mod core;
31/// A traitified version of `ghost_cell`.
32///
33/// To use this, simply construct a [`TokenCell`](crate::prelude::TokenCell) using a [`GhostToken`](crate::ghost::GhostToken) obtained with the [`TokenTrait::with_token`](crate::prelude::TokenTrait::with_token) constructor.
34pub mod ghost;
35/// The macros to construct tokens.
36pub mod macros;
37/// Because monads are cool.
38pub mod monads;
39
40/// Support module for the [`runtime_token`] macro.
41pub mod runtime_token_support;
42
43runtime_token!(
44 /// The default runtime-checked token type.
45 ///
46 /// Because this token type is checked at runtime, it can make sense to have a global token type for your whole application.
47 ///
48 /// And because this runtime token is backed by a `u64`, it would take you 60 years continuously instantiating them at 10GHz
49 /// (which is unfeasible with existing hardware) before an overflow may cause multiple tokens to share the same runtime identifier;
50 /// so you can safely assume that this token type will never let you access a cell that you shouldn't be accessing.
51 pub RuntimeToken: u64
52);