#lazy-evaluation #static #lazy

no-std generic_once_cell

A bring-your-own-mutex version of once_cell

2 releases

0.1.1 Dec 15, 2022
0.1.0 Nov 10, 2022

#2916 in Rust patterns

Download history 115/week @ 2023-11-24 306/week @ 2023-12-01 349/week @ 2023-12-08 450/week @ 2023-12-15 95/week @ 2023-12-22 141/week @ 2023-12-29 350/week @ 2024-01-05 481/week @ 2024-01-12 414/week @ 2024-01-19 517/week @ 2024-01-26 638/week @ 2024-02-02 588/week @ 2024-02-09 738/week @ 2024-02-16 773/week @ 2024-02-23 641/week @ 2024-03-01 472/week @ 2024-03-08

2,721 downloads per month
Used in 3 crates (2 directly)

MIT/Apache

25KB
244 lines

generic_once_cell

Crates.io docs.rs CI

generic_once_cell is a generic no_std version of once_cell. Internal synchronization for initialization is provided as type parameter via custom mutexes based on lock_api. This makes it suitable for use in complex no_std scenarios where once_cell's critical-section support and once_cell::race are not sufficient.

The core API looks roughly like this:

impl<R: lock_api::RawMutex, T> OnceCell<R, T> {
    const fn new() -> Self { ... }
    fn set(&self, value: T) -> Result<(), T> { ... }
    fn get(&self) -> Option<&T> { ... }
}

More patterns and use-cases are in the docs!

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~160KB