What Is the Difference Between Send and Sync Traits?

Send allows transferring ownership across threads, while Sync allows sharing references across threads safely.

Send means a type can be transferred across threads, while Sync means a reference to the type can be shared across threads. Send is implemented for types that can safely move ownership to another thread, and Sync is automatically implemented for types where T is Send, allowing &T to be shared.

use std::thread;

fn main() {
    let data = String::from("hello");
    thread::spawn(move || {
        println!("{}", data);
    }).join().unwrap();
}