expression
LocalSet: same-thread task scheduling
A local task set can drive non-Send futures on the same thread. Ordinary tokio::spawn still requires Send; use spawn_local within the set. The example joins its local task before leaving the set. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): 4 Common mistake: Assuming a current-thread runtime alone removes the Send bound of tokio::spawn.
Formal Syntax & Structure
rust syntaxrust
LocalSet::new().run_until(future).awaitWorking Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { let local = tokio::task::LocalSet::new(); local.run_until(async { let label = std::rc::Rc::new(String::from("note")); let task = tokio::task::spawn_local(async move { tokio::task::yield_now().await; label.len() }); println!("{}", task.await.unwrap()); }).await;}