On this page
Send
Prev: From | Up: builtins | Next: Sync
Rel: builtins, Ownership, Borrowing & Lifetimes
Ref: Rust Docs — Send
Tags: #public #prog #rust #builtins #tier/standard
Availability
Built-in / Prelude (Auto Marker Trait) — available with zero use imports.
Syntax & Overview
unsafe auto trait Send {}
Marks types safe to transfer ownership across OS thread boundaries.
Notes & Pitfalls
- Auto-trait for cross-thread ownership transfer: Almost all types are
Sendautomatically unless they contain non-thread-safe primitives likeRc<T>or raw pointers. - Required by
std::thread::spawn: Capturing a non-Sendvalue in a spawned thread fails at compile time, preventing data races.
Example
use std::thread;
fn main() {
let msg = String::from("moved to worker"); // String is Send
let handle = thread::spawn(move || msg.len());
assert_eq!(handle.join().unwrap(), 15);
}
Linked from
Related notes
- tuts/rust/builtins/From Linked here; links to this page; shared tags: #builtins, #prog, #rust, #tier
- tuts/rust/builtins/Sync Linked here; links to this page; shared tags: #builtins, #prog, #rust, #tier
- tuts/rust/builtins Linked here; links to this page; shared tags: #builtins, #prog, #rust
- tuts/rust/ownership_and_internals/ownership_borrowing_and_lifetimes Linked here; shared tags: #prog, #rust
- tuts/rust/builtins/Clone shared tags: #builtins, #prog, #rust, #tier
- tuts/rust/builtins/Copy shared tags: #builtins, #prog, #rust, #tier
- tuts/rust/builtins/Drop shared tags: #builtins, #prog, #rust, #tier
- tuts/rust/builtins/Iterator shared tags: #builtins, #prog, #rust, #tier
- tuts/rust/builtins/macro_rules shared tags: #builtins, #prog, #rust, #tier
- tuts/rust/builtins/match shared tags: #builtins, #prog, #rust, #tier