davenport

Function with_thread_local_workspace

Source
pub fn with_thread_local_workspace<W: 'static + Default, T>(
    workspace: &'static LocalKey<RefCell<Workspace>>,
    f: impl FnOnce(&mut W) -> T,
) -> T
Expand description

Runs the provided closure with the thread-local workspace as an argument.

This simplifies working with Workspace when it’s stored as a thread-local variable.

Note that the typed workspace must have a Default implementation.

See the crate-level documentation for typical usage examples.

§Panics

Panics if used recursively with the same workspace variable, as it relies on mutably borrowing through RefCell. See the crate-level documentation for a discussion of this limitation.