@@ -238,7 +238,6 @@ macro_rules! tls(
238
238
)
239
239
240
240
pub struct Key <T : 'static > { /* ... */ }
241
- pub struct Ref <T : 'static > { /* ... */ }
242
241
243
242
impl <T : 'static > Key <T > {
244
243
/// Access this TLS variable, lazily initializing it if necessary.
@@ -249,10 +248,8 @@ impl<T: 'static> Key<T> {
249
248
///
250
249
/// This function can return `None` for the same reasons of static TLS
251
250
/// returning `None` (destructors are running or may have run).
252
- pub fn get (& 'static self ) -> Option <Ref < T >> { /* ... */ }
251
+ pub fn with < R > (& 'static self , f : | Option <& T > | -> R ) -> R { /* ... */ }
253
252
}
254
-
255
- impl <T : 'static > Deref <T > for Ref <T > { /* ... */ }
256
253
```
257
254
258
255
### Destructors
@@ -279,9 +276,14 @@ some of the minor downsides.
279
276
280
277
### Variations
281
278
282
- Like the scoped TLS varations, the primary way this API could be altered would
283
- be to return ` Ref<T> ` instead of an ` Option ` from ` get ` , while then providing a
284
- function to test whether a value is being destroyed.
279
+ Like the scoped TLS variation, this key has a ` with ` function instead of the
280
+ normally expected ` get ` function (returning a reference). One possible
281
+ alternative would be to yield ` &T ` instead of ` Option<&T> ` and ` panic! ` if the
282
+ variable has been destroyed. Another possible alternative is to have a ` get `
283
+ function returning a ` Ref<T> ` . Currently this is unsafe, however, as there is no
284
+ way to ensure that ` Ref<T> ` does not satisfy ` 'static ` . If the returned
285
+ reference satisfies ` 'static ` , then it's possible for TLS values to reference
286
+ each other after one has been destroyed, causing a use-after-free.
285
287
286
288
# Drawbacks
287
289
0 commit comments