core API: Lazy

This commit is contained in:
awiouy 2018-02-12 20:20:43 +01:00
parent aed4fe32d8
commit 6a9084b00c

View file

@ -39,17 +39,17 @@ macro_rules! component {
use std::cell::UnsafeCell;
use std::sync::Mutex;
pub struct Lazy<T>(Mutex<bool>, UnsafeCell<Option<T>>);
pub(crate) struct Lazy<T>(Mutex<bool>, UnsafeCell<Option<T>>);
unsafe impl<T: Sync> Sync for Lazy<T> {}
unsafe impl<T: Send> Send for Lazy<T> {}
#[cfg_attr(feature = "cargo-clippy", allow(mutex_atomic))]
impl<T> Lazy<T> {
pub fn new() -> Lazy<T> {
pub(crate) fn new() -> Lazy<T> {
Lazy(Mutex::new(false), UnsafeCell::new(None))
}
pub fn get<F: FnOnce() -> T>(&self, f: F) -> &T {
pub(crate) fn get<F: FnOnce() -> T>(&self, f: F) -> &T {
let mut inner = self.0.lock().unwrap();
if !*inner {
unsafe {