Email me

Rust errors / Build and Cargo

Rust build error · checked with Rust 1.99.0

error: future cannot be sent between threads safely

error: future cannot be sent between threads safely

What it meanstokio::spawn needs a future that can move between threads (Send). Something not thread-safe, often a std MutexGuard or an Rc, is held across an .await.

Why it happens

  • Holding a std::sync::MutexGuard across .await.
  • Keeping an Rc, RefCell borrow or raw pointer alive across .await.

How to fix it

1. Drop the guard before awaiting

Scope it so it ends before the await.

let value = {
    let g = state.lock().unwrap();
    g.clone()
}; // guard dropped here
send(value).await;

2. Use tokio's Mutex when you must hold it across await

let g = state.lock().await;  // tokio::sync::Mutex

3. Use Arc instead of Rc

let shared = std::sync::Arc::new(data);

Other wordings of this error

future cannot be sent between threads safely, future is not Send, has type which is not Send, MutexGuard is not Send tokio spawn

Other build errors

Up next

Find the right pagePaste any Rust errorCompiler codes and build errors in one finder.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ