mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-26 22:53:15 -04:00
Removes the once_cell dependency, instead using std::sync::OnceLock and a minimal polyfill for std::sync::LazyLock, which may be stabilized soon (see rust-lang/rust#121377). This should not require a bump in MSRV, as OnceLock was stabilized in 1.70, which this crate is using.
31 lines
654 B
Rust
31 lines
654 B
Rust
// A poly-fill for `lazy_cell`
|
|
// Replace with std::sync::LazyLock when https://github.com/rust-lang/rust/issues/109736 is stablized.
|
|
|
|
// This isn't used on every platform, which can come up as dead code warnings.
|
|
#![allow(dead_code)]
|
|
|
|
use std::ops::Deref;
|
|
use std::sync::OnceLock;
|
|
|
|
pub(crate) struct Lazy<T> {
|
|
cell: OnceLock<T>,
|
|
init: fn() -> T,
|
|
}
|
|
|
|
impl<T> Lazy<T> {
|
|
pub const fn new(f: fn() -> T) -> Self {
|
|
Self {
|
|
cell: OnceLock::new(),
|
|
init: f,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<T> Deref for Lazy<T> {
|
|
type Target = T;
|
|
#[inline]
|
|
fn deref(&self) -> &'_ T {
|
|
self.cell.get_or_init(self.init)
|
|
}
|
|
}
|