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

#195 in Memory management

Download history 14568/week @ 2024-10-15 15901/week @ 2024-10-22 12309/week @ 2024-10-29 12417/week @ 2024-11-05 11445/week @ 2024-11-12 12583/week @ 2024-11-19 10593/week @ 2024-11-26 14354/week @ 2024-12-03 15826/week @ 2024-12-10 11846/week @ 2024-12-17 5066/week @ 2024-12-24 6747/week @ 2024-12-31 11522/week @ 2025-01-07 14976/week @ 2025-01-14 13082/week @ 2025-01-21 12036/week @ 2025-01-28

53,542 downloads per month
Used in 78 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