std::thread_local! [-] [+] [src]

macro_rules! thread_local {
    (static $name:ident: $t:ty = $init:expr) => (
        static $name: ::std::thread_local::Key<$t> = {
            use std::cell::UnsafeCell as __UnsafeCell;
            use std::thread_local::__impl::KeyInner as __KeyInner;
            use std::option::Option as __Option;
            use std::option::Option::None as __None;

            __thread_local_inner!(static __KEY: __UnsafeCell<__Option<$t>> = {
                __UnsafeCell { value: __None }
            });
            fn __init() -> $t { $init }
            fn __getit() -> &'static __KeyInner<__UnsafeCell<__Option<$t>>> {
                &__KEY
            }
            ::std::thread_local::Key { inner: __getit, init: __init }
        };
    );
    (pub static $name:ident: $t:ty = $init:expr) => (
        pub static $name: ::std::thread_local::Key<$t> = {
            use std::cell::UnsafeCell as __UnsafeCell;
            use std::thread_local::__impl::KeyInner as __KeyInner;
            use std::option::Option as __Option;
            use std::option::Option::None as __None;

            __thread_local_inner!(static __KEY: __UnsafeCell<__Option<$t>> = {
                __UnsafeCell { value: __None }
            });
            fn __init() -> $t { $init }
            fn __getit() -> &'static __KeyInner<__UnsafeCell<__Option<$t>>> {
                &__KEY
            }
            ::std::thread_local::Key { inner: __getit, init: __init }
        };
    );
}

Declare a new thread local storage key of type std::thread_local::Key.