scoped_static
Lift references into
'static
safely — at runtime.
scoped_static
allows temporarily extending a reference’s lifetime to 'static
using runtime safety checks.
This enables you to safely spawn asynchronous tasks, threads, or other 'static
contexts without running into borrow checker limitations — while still avoiding undefined behavior.
Motivation
Rust’s lifetime system ensures safety at compile time, but sometimes you need to move a non-'static
reference into an async task or thread:
async
This fails because the reference to ref_value
isn’t 'static
.
scoped_static
solves this by allowing you to lift a reference to 'static
under the protection of a scope guard that enforces correct drop order at runtime.
Example
use ;
async
See ScopeGuard and UncheckedScopeGuard for more info.