mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-05-17 08:02:38 +02:00
Mention that Send and Sync are unsafe traits.
This commit is contained in:
parent
81cf02ffbe
commit
5dd87192e8
@ -7,16 +7,17 @@ How does Rust know to forbid shared access across thread? The answer is in two t
|
|||||||
* [`Sync`][2]: a type `T` is `Sync` if it is safe to move a `&T` across a thread
|
* [`Sync`][2]: a type `T` is `Sync` if it is safe to move a `&T` across a thread
|
||||||
boundary.
|
boundary.
|
||||||
|
|
||||||
Both traits are not to be implemented. They are implemented automatically when
|
`Send` and `Sync` are [unsafe traits][3]. The compiler will automatically derive them for your types
|
||||||
the compiler determines it’s appropriate.
|
as long as they only contain `Send` and `Sync` types. You can also implement them manually when you
|
||||||
|
know it is valid.
|
||||||
|
|
||||||
[1]: https://doc.rust-lang.org/std/marker/trait.Send.html
|
[1]: https://doc.rust-lang.org/std/marker/trait.Send.html
|
||||||
[2]: https://doc.rust-lang.org/std/marker/trait.Sync.html
|
[2]: https://doc.rust-lang.org/std/marker/trait.Sync.html
|
||||||
|
[3]: ../unsafe/unsafe-traits.md
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
|
|
||||||
* One can think of these traits as markers that the type has certain
|
* One can think of these traits as markers that the type has certain thread-safety properties.
|
||||||
thread-safety properties.
|
|
||||||
* They can be used in the generic constraints as normal traits.
|
* They can be used in the generic constraints as normal traits.
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user