diff --git a/Cargo.toml b/Cargo.toml index bb241ff..c9c9b1a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,6 @@ Library implementation of the standard library's old `scoped_thread_local!` macro for providing scoped access to thread local storage (TLS) so any type can be stored into TLS. """ + +[features] +nightly = [] \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 9d4ba5b..419ab65 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,12 +44,15 @@ //! ``` #![deny(missing_docs, warnings)] +#![cfg_attr(feature = "nightly", feature(macro_vis_matcher))] +#![cfg_attr(feature = "nightly", feature(allow_internal_unstable))] use std::cell::Cell; use std::marker; use std::thread::LocalKey; #[macro_export] +#[cfg(not(feature = "nightly"))] macro_rules! scoped_thread_local { (static $name:ident: $ty:ty) => ( static $name: $crate::ScopedKey<$ty> = $crate::ScopedKey { @@ -64,6 +67,23 @@ macro_rules! scoped_thread_local { ) } +#[macro_export] +#[allow_internal_unstable] +#[cfg(feature = "nightly")] +macro_rules! scoped_thread_local { + ($vis:vis static $name:ident: $ty:ty) => ( + $vis static $name: $crate::ScopedKey<$ty> = $crate::ScopedKey { + inner: { + thread_local!(static FOO: ::std::cell::Cell = { + ::std::cell::Cell::new(0) + }); + &FOO + }, + _marker: ::std::marker::PhantomData, + }; + ) +} + /// Type representing a thread local storage key corresponding to a reference /// to the type parameter `T`. ///