What are marker traits

Marker traits are empty traits in Rust that signal to the compiler that a type has specific safety guarantees, such as being thread-safe.

Marker traits are traits with no methods that serve as compile-time guarantees for specific behaviors, such as thread safety or data transferability. In Rust, the Send and Sync traits are the primary marker traits used to ensure types can be safely shared across threads. You implement these traits automatically by deriving them or explicitly by using unsafe impl when you are certain the type meets the safety requirements.

// Example: A type that is Send but not Sync
struct NotSync {
    data: i32,
}

// Explicitly implementing marker traits (requires unsafe)
unsafe impl Send for NotSync {}
// Sync is not implemented, so NotSync cannot be shared via &T across threads