@@ -22,14 +22,20 @@ enum ThisOrThat<T, U> {
22
22
23
23
/// `LazyTransform<T, U>` is a synchronized holder type, that holds a value of
24
24
/// type T until it is lazily converted into a value of type U.
25
- pub struct LazyTransform < T , U > {
25
+ pub struct LazyTransform < T , U >
26
+ where T : Sync ,
27
+ U : Sync
28
+ {
26
29
initialized : AtomicBool ,
27
30
lock : Mutex < ( ) > ,
28
31
value : UnsafeCell < Option < ThisOrThat < T , U > > > ,
29
32
}
30
33
31
34
// Implementation details.
32
- impl < T , U > LazyTransform < T , U > {
35
+ impl < T , U > LazyTransform < T , U >
36
+ where T : Sync ,
37
+ U : Sync
38
+ {
33
39
fn extract < ' a > ( & ' a self ) -> Option < & ' a U > {
34
40
// Make sure we're initialized first!
35
41
match unsafe { ( * self . value . get ( ) ) . as_ref ( ) } {
@@ -41,7 +47,10 @@ impl<T, U> LazyTransform<T, U> {
41
47
}
42
48
43
49
// Public API.
44
- impl < T , U > LazyTransform < T , U > {
50
+ impl < T , U > LazyTransform < T , U >
51
+ where T : Sync ,
52
+ U : Sync
53
+ {
45
54
/// Construct a new, untransformed `LazyTransform<T, U>` with an argument of
46
55
/// type T.
47
56
pub fn new ( t : T ) -> LazyTransform < T , U > {
@@ -103,15 +112,23 @@ impl<T, U> LazyTransform<T, U> {
103
112
}
104
113
}
105
114
106
- unsafe impl < T , U > Sync for LazyTransform < T , U > { }
115
+ unsafe impl < T , U > Sync for LazyTransform < T , U >
116
+ where T : Sync ,
117
+ U : Sync
118
+ {
119
+ }
107
120
108
121
/// `Lazy<T>` is a lazily initialized synchronized holder type. You can think
109
122
/// of it as a LazyTransform where the initial type doesn't exist.
110
- pub struct Lazy < T > {
123
+ pub struct Lazy < T >
124
+ where T : Sync
125
+ {
111
126
inner : LazyTransform < ( ) , T > ,
112
127
}
113
128
114
- impl < T > Lazy < T > {
129
+ impl < T > Lazy < T >
130
+ where T : Sync
131
+ {
115
132
/// Construct a new, uninitialized `Lazy<T>`.
116
133
pub fn new ( ) -> Lazy < T > {
117
134
Lazy { inner : LazyTransform :: new ( ( ) ) }
0 commit comments