thread_local_scope 1.0.0

Scoped access to thread local storage
Documentation

thread_local_scope

Rust with MIRI docs.rs

Provides a token type LocalScope that guards access to thread local storage, avoiding the need for a separate closure for every access.

LOCAL_ONE.try_with(|one| {
    LOCAL_TWO.try_with(|two| {
        ...
    })
})??

becomes

local_scope(|scope| {
    let one = scope.try_access(&LOCAL_ONE)?;
    let two = scope.try_access(&LOCAL_TWO)?;
    ...
})?

Scope

This crate is deliberately minimal. Other crates may use this crate to create more advanced abstractions over thread local storage.