#thread-local #static #lazy-evaluation #macro

ref_thread_local

A macro for declaring thread-local statics like using both of lazy_static! and RefCell

3 unstable releases

Uses old Rust 2015

0.1.1 Nov 16, 2021
0.1.0 Jan 15, 2021
0.0.0 Oct 1, 2018

#1073 in Rust patterns

Download history 1599/week @ 2023-11-23 1109/week @ 2023-11-30 1498/week @ 2023-12-07 1438/week @ 2023-12-14 1979/week @ 2023-12-21 1210/week @ 2023-12-28 2577/week @ 2024-01-04 1575/week @ 2024-01-11 1130/week @ 2024-01-18 1874/week @ 2024-01-25 1496/week @ 2024-02-01 942/week @ 2024-02-08 1388/week @ 2024-02-15 1807/week @ 2024-02-22 730/week @ 2024-02-29 338/week @ 2024-03-07

4,380 downloads per month
Used in 20 crates (12 directly)

MIT license

19KB
352 lines

ref_thread_local.rs

A macro for declaring thread-local statics like using both of lazy_static! and RefCell

Using this macro, you can have thread-local statics be referenced by borrow() function like using a RefCell.

You may also initialize or destroy a static variable at any time you like.

Travis-CI Status Latest version Documentation License

Minimum supported rustc

1.30.0+

Getting Started

ref_thread_local.rs is available on crates.io. It is recommended to look there for the newest released version, as well as links to the newest builds of the docs.

At the point of the last update of this README, the latest published version could be used like this:

Add the following dependency to your Cargo manifest...

[dependencies]
ref_thread_local = "0.0"

...and see the docs for how to use it.

Example

#[macro_use]
extern crate ref_thread_local;
use ref_thread_local::RefThreadLocal;

ref_thread_local! {
    static managed NUMBER: i32 = 233;
}

fn main() {
    let x = NUMBER.borrow(); // a Ref<'a, i32>
    println!("The number is {}.", x);
}

License

Licensed under of

No runtime deps