How does Rust know to forbid shared access across thread? The answer is in two traits:
Send: a type
Sendif it is safe to move a
Tacross a thread boundary.
Sync: a type
Syncif it is safe to move a
&Tacross a thread boundary.
Sync are unsafe traits. The compiler will automatically derive them for your types
as long as they only contain
Sync types. You can also implement them manually when you
know it is valid.
- One can think of these traits as markers that the type has certain thread-safety properties.
- They can be used in the generic constraints as normal traits.