What is Send and Sync in async Rust

Send allows moving data between threads, while Sync allows sharing references between threads safely in Rust.

Send and Sync are unsafe marker traits that determine if a type can be transferred across threads or shared between threads safely. Send means ownership can move to another thread, while Sync means a reference (&T) can be shared across threads. Most standard types implement these automatically, but you must manually implement them for custom types using unsafe if they are thread-safe.

use std::thread;

struct MyData {
    value: i32,
}

// MyData implements Send and Sync by default because i32 does.
fn main() {
    let data = MyData { value: 42 };
    thread::spawn(move || {
        println!("Value: {}", data.value);
    }).join().unwrap();
}