Book 1 · Lesson 1.10

Send and Sync traits

  • Define Send and Sync in plain language
  • Classify common millipede types as Send/Sync
  • Explain why Axum State must be Send + Sync

Prerequisites: 1.9

Thread safety in Rust is expressed as traits, not comments.

TraitMeaning
SendSafe to move to another thread
SyncSafe to share &T across threads

Most Axum handlers return impl Future + Send because Tokio may run continuations on different worker threads.

Service boundary rules

TypeTypical useSend / Sync
StringMove into Kafka payloadMove only — not shared by ref across threads
Arc<Mutex<Metrics>>Shared countersSend + Sync when inner T is
Rc<Config>Single-thread cacheNeither — use Arc for shared state

Toggle types in SendSyncExplorer.

Gateway vs ingestion

Shared connection pools (Postgres, Redis) live in State — cloned per handler, internally synchronized.

Teach-back prompt

Why is Rc<T> forbidden in a tokio::spawn future?

Service boundary rules

Lesson 1.10 check

1. Sync means…