mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
core API: Lazy
This commit is contained in:
parent
aed4fe32d8
commit
6a9084b00c
1 changed files with 3 additions and 3 deletions
|
@ -39,17 +39,17 @@ macro_rules! component {
|
||||||
use std::cell::UnsafeCell;
|
use std::cell::UnsafeCell;
|
||||||
use std::sync::Mutex;
|
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: Sync> Sync for Lazy<T> {}
|
||||||
unsafe impl<T: Send> Send for Lazy<T> {}
|
unsafe impl<T: Send> Send for Lazy<T> {}
|
||||||
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(mutex_atomic))]
|
#[cfg_attr(feature = "cargo-clippy", allow(mutex_atomic))]
|
||||||
impl<T> Lazy<T> {
|
impl<T> Lazy<T> {
|
||||||
pub fn new() -> Lazy<T> {
|
pub(crate) fn new() -> Lazy<T> {
|
||||||
Lazy(Mutex::new(false), UnsafeCell::new(None))
|
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();
|
let mut inner = self.0.lock().unwrap();
|
||||||
if !*inner {
|
if !*inner {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
Loading…
Reference in a new issue