https://github.com/mkroening/generic_once_cell
A bring-your-own-mutex version of once_cell.
https://github.com/mkroening/generic_once_cell
lazy-evaluation rust
Last synced: 3 months ago
JSON representation
A bring-your-own-mutex version of once_cell.
- Host: GitHub
- URL: https://github.com/mkroening/generic_once_cell
- Owner: mkroening
- License: apache-2.0
- Created: 2022-11-09T11:21:58.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-11T12:16:49.000Z (almost 2 years ago)
- Last Synced: 2024-10-31T11:52:28.490Z (8 months ago)
- Topics: lazy-evaluation, rust
- Language: Rust
- Homepage: https://crates.io/crates/generic_once_cell
- Size: 18.6 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# generic_once_cell
[](https://crates.io/crates/generic_once_cell)
[](https://docs.rs/generic_once_cell)
[](https://github.com/mkroening/generic_once_cell/actions/workflows/ci.yml)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:
```rust
impl OnceCell {
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]!
[once_cell]: https://crates.io/crates/once_cell
[lock_api]: https://crates.io/crates/lock_api
[once_cell's `critical-section` support]: https://github.com/matklad/once_cell/blob/master/CHANGELOG.md#1160
[`once_cell::race`]: https://docs.rs/once_cell/1.16.0/once_cell/race/index.html
[docs]: https://docs.rs/generic_once_cell## License
Licensed under either of
* Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)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.