9 stable releases

1.5.0 Mar 29, 2023
1.4.2 Jan 18, 2023
1.3.0 Nov 8, 2022
1.1.0 Sep 10, 2021
1.0.0 Aug 27, 2021

#110 in Memory management

Download history 5258/week @ 2024-01-12 6845/week @ 2024-01-19 7611/week @ 2024-01-26 8672/week @ 2024-02-02 9871/week @ 2024-02-09 6772/week @ 2024-02-16 8552/week @ 2024-02-23 9804/week @ 2024-03-01 10081/week @ 2024-03-08 9409/week @ 2024-03-15 9443/week @ 2024-03-22 6668/week @ 2024-03-29 11598/week @ 2024-04-05 12211/week @ 2024-04-12 10458/week @ 2024-04-19 7513/week @ 2024-04-26

43,741 downloads per month
Used in 55 crates (via zenoh-keyexpr)

EPL-2.0 license

20KB
456 lines

This library provides an alternative to ghost-cell which uses concrete types instead of lifetimes for branding.

This allows a more convenient usage, where cells and tokens can be constructed independently, with the same compile-time guarantees as 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.

To this end, this crate provides the generate_token macro, which will create a ZST which can only be constructed using TokenTrait::new.


lib.rs:

This library provides an alternative to ghost-cell which uses concrete types instead of lifetimes for branding.

This allows a more convenient usage, where cells and tokens can be constructed independently, with the same compile-time guarantees as 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.

To this end, this crate provides the generate_token macro, which will create a ZST which can only be constructed using TokenTrait::aquire, which is generated to guarantee no other token exists before returning the token. This is done by checking a static AtomicBool flag, which is the only runtime cost of these tokens.

Dependencies