liveBook · Manning

Send

As explained in Code Like a Pro in Rust

Send is a Rust marker trait indicating that a value can be transferred safely between threads.

Send is a Rust marker trait for values that can be moved safely between threads. The compiler derives it when appropriate; application code usually composes Arc, Mutex, or RwLock rather than implementing it directly. section 6.5

Use Send-related reasoning when handling shared state:

  • Move a value between threads only through a type that implements Send. section 6.5
  • Use Sync for shared references; combine Arc with synchronization primitives when ownership and thread sharing intersect. section 6.5

Global test counter

A direct mutable static fails because concurrent mutation can violate aliasing rules. An atomic counter addresses the operation itself, while Arc and lazy_static address ownership and runtime initialization: clone the Arc inside each test, then call fetch_add.

How Code Like a Pro in Rust covers it

How deep it goes
Defines Send and contrasts Sync, then stops short of trait internals and focuses on Arc-based implementation consequences.
Examples
Uses mutable static counters, AtomicI32, Arc cloning, lazy_static initialization, and mutex-guarded tests.
What it assumes
Assumes Rust familiarity and introduces Send alongside multithreading, ownership, shared state, and compiler safety diagnostics.
What you can do after
Apply Send via Arc, atomics, Mutex, RwLock, and lazy_static when compiling thread-safe shared state.
How it connects
Connects Send with Sync, Arc, Mutex, RwLock, atomics, ownership, and lazy initialization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Code Like a Pro in Rust. The section links point to the parts of the book it draws on.