#lazy-evaluation #static

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

#2832 in Rust patterns

Download history 766/week @ 2024-07-23 806/week @ 2024-07-30 584/week @ 2024-08-06 430/week @ 2024-08-13 829/week @ 2024-08-20 956/week @ 2024-08-27 573/week @ 2024-09-03 704/week @ 2024-09-10 406/week @ 2024-09-17 570/week @ 2024-09-24 707/week @ 2024-10-01 577/week @ 2024-10-08 427/week @ 2024-10-15 489/week @ 2024-10-22 293/week @ 2024-10-29 459/week @ 2024-11-05

1,729 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