What is Send and Sync exactly?
⚓ Rust 📅 2025-06-27 👤 surdeus 👁️ 18Hi folks, you're the best community I have ever seen. I asked question at title but let me explain what exactly I'm looking for.
1- There isn't anything source code of these traits. What is there inside of Send and Sync traits?
pub unsafe auto trait Send {
// empty.
}
pub unsafe auto trait Sync {
// FIXME(estebank): once support to add notes in `rustc_on_unimplemented`
// lands in beta, and it has been extended to check whether a closure is
// anywhere in the requirement chain, extend it as such (#48534):
// ```
// on(
// closure,
// note="`{Self}` cannot be shared safely, consider marking the closure `move`"
// ),
// ```
// Empty
}
2- I can't use derive macro for Send and Sync but I can create impl blocks for these. Probably derive macro can't derive unsafe blocks. Also this macro's source code is empty too. What is exactly makes this macro? Why it can't create unsafe implementations?
pub macro derive($item:item) {
/* compiler built-in */
}
....
// I can't do that:
#[derive(Debug, Send, Sync)]
pub struct SendSyncExample {
pub counter: Arc<Mutex<i32>>,
}
// but I can do that:
#[derive(Debug)]
pub struct SendSyncExample {
pub counter: Arc<Mutex<i32>>,
}
unsafe impl Send for SendSyncExample {}
unsafe impl Sync for SendSyncExample {}
Thanks to all brothers.
1 post - 1 participant
🏷️ rust_feed