impl<T: 'static> RacyLock<T> { #[cfg(std)] /// Creates a new [`RacyLock`], which will initialize using the provided `init` function. pubconstfn new(init: fn() -> T) -> Self { Self {
inner: LazyLock::new(init),
}
}
#[cfg(no_std)] /// Creates a new [`RacyLock`], which will initialize using the provided `init` function. pubconstfn new(init: fn() -> T) -> Self { Self {
inner: OnceBox::new(),
init,
}
}
}
#[cfg(std)] impl<T: 'static> core::ops::Deref for RacyLock<T> { type Target = T;
/// Loads the internal value, initializing it if required. fn deref(&self) -> &Self::Target {
&self.inner
}
}
#[cfg(no_std)] impl<T: 'static> core::ops::Deref for RacyLock<T> { type Target = T;
/// Loads the internal value, initializing it if required. fn deref(&self) -> &Self::Target { self.inner.get_or_init(|| Box::new((self.init)()))
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.