Marker Traits
How does Rust know to forbid shared access across threads? The answer is in two traits:
Send
and Sync
are unsafe traits. The compiler will automatically derive them for your types as long as they only contain Send
and Sync
types. You can also implement them manually when you know it is valid.
- 不妨将这些特征视为类型包含某些线程安全属性的标记。
- 它们可以在泛型约束中作为常规特征使用。