1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
mod once_self_cell;
pub trait OnceCellCompatible<T> {
fn new() -> Self;
fn get(&self) -> Option<&T>;
fn get_or_init<F>(&self, f: F) -> &T
where
F: FnOnce() -> T;
fn take(&mut self) -> Option<T>;
}
pub mod unsync {
use crate::once_self_cell::DependentInner;
use once_cell::unsync::OnceCell;
#[derive(Debug)]
pub struct UnsyncOnceCell(OnceCell<DependentInner>);
impl crate::OnceCellCompatible<DependentInner> for UnsyncOnceCell {
fn new() -> Self {
UnsyncOnceCell(OnceCell::<DependentInner>::new())
}
fn get(&self) -> Option<&DependentInner> {
self.0.get()
}
fn get_or_init<F>(&self, f: F) -> &DependentInner
where
F: FnOnce() -> DependentInner,
{
self.0.get_or_init(f)
}
fn take(&mut self) -> Option<DependentInner> {
self.0.take()
}
}
pub type OnceSelfCell<Owner, DependentStaticLifetime> =
crate::once_self_cell::OnceSelfCell<Owner, DependentStaticLifetime, UnsyncOnceCell>;
}
pub mod sync {
use crate::once_self_cell::DependentInner;
use once_cell::sync::OnceCell;
#[derive(Debug)]
pub struct SyncOnceCell(OnceCell<DependentInner>);
impl crate::OnceCellCompatible<DependentInner> for SyncOnceCell {
fn new() -> Self {
SyncOnceCell(OnceCell::<DependentInner>::new())
}
fn get(&self) -> Option<&DependentInner> {
self.0.get()
}
fn get_or_init<F>(&self, f: F) -> &DependentInner
where
F: FnOnce() -> DependentInner,
{
self.0.get_or_init(f)
}
fn take(&mut self) -> Option<DependentInner> {
self.0.take()
}
}
unsafe impl Send for SyncOnceCell {}
unsafe impl Sync for SyncOnceCell {}
pub type OnceSelfCell<Owner, DependentStaticLifetime> =
crate::once_self_cell::OnceSelfCell<Owner, DependentStaticLifetime, SyncOnceCell>;
}
pub mod custom {
pub type OnceSelfCell<Owner, DependentStaticLifetime, DependentCell> =
crate::once_self_cell::OnceSelfCell<Owner, DependentStaticLifetime, DependentCell>;
}