1 unstable release

Uses old Rust 2015

0.1.0 May 24, 2017

#17 in #thread-local-storage

Download history 29/week @ 2024-03-11 48/week @ 2024-03-18 42/week @ 2024-03-25 82/week @ 2024-04-01 4/week @ 2024-04-08 26/week @ 2024-04-15 30/week @ 2024-04-22 32/week @ 2024-04-29 18/week @ 2024-05-06 24/week @ 2024-05-13 33/week @ 2024-05-20 18/week @ 2024-05-27 13/week @ 2024-06-03 66/week @ 2024-06-10 23/week @ 2024-06-17 15/week @ 2024-06-24

118 downloads per month
Used in 3 crates (via per-thread-object)


141 lines


Build Status


Per-object thread local storage.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


Per-object thread local storage.

The ThreadLocal type which stores a distinct (nullable) value of some type for each thread that accesses it.

A thread's values are destroyed when it exits, but the values associated with a ThreadLocal instance are not destroyed when it is dropped. These are in some ways the opposite semantics of those provided by the thread_local crate, where values are cleaned up when a ThreadLocal object is dropped, but not when individual threads exit.

Because of this, this crate is an appropriate choice for use cases where you have long lived ThreadLocal instances which are widely shared among threads that are created and destroyed through the runtime of a program, while the thread_local crate is an appropriate choice for short lived values.


use std::sync::Arc;
use std::thread;
use thread_local_object::ThreadLocal;

let tls = Arc::new(ThreadLocal::new());


let tls2 = tls.clone();
thread::spawn(move || {
    // the other thread doesn't see the 1
    assert_eq!(tls2.get_cloned(), None);

// we still see our original value
assert_eq!(tls.get_cloned(), Some(1));