std::thread_local

Macro std::thread_local

macro_rules! thread_local {
    () => { ... };
    ($(#[$attr:meta])* static $name:ident: $t:ty = $init:expr; $($rest:tt)*) => { ... };
    ($(#[$attr:meta])* static $name:ident: $t:ty = $init:expr) => { ... };
    ($(#[$attr:meta])* pub static $name:ident: $t:ty = $init:expr; $($rest:tt)*) => { ... };
    ($(#[$attr:meta])* pub static $name:ident: $t:ty = $init:expr) => { ... };
}

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

Syntax

The macro wraps any number of static declarations and makes them thread local. Each static may be public or private, and attributes are allowed. Example:

use std::cell::RefCell;
thread_local! {
    pub static FOO: RefCell<u32> = RefCell::new(1);

    #[allow(unused)]
    static BAR: RefCell<f32> = RefCell::new(1.0);
}

See LocalKey documentation for more information.

© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/macro.thread_local.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部