Send is a #202204061235 that allows the ownership of implemented types to be transferred safely in a multithreading environment#. Almost all Rust types are implemented with Send trait, except #202206221720, and if the user’s custom type is composed of those types, then it will automatically have the Send trait. There is no method needed to be implemented in this trait.
Rust Send
- Rust Trait
-
Rust Sync
Sync is a #202204061235 that allows the type to be referenced in a multithreading environment#. Rust primitive types has this trait implemented by default, and same as 202207172159, if the type is entirely composed of these types, then it will have this trait implicitly. Some types such as raw pointers, #202206221720 and
Cell<T>
related types (including #202206232210) doesn’t implement this trait. -
Reference Counting Pointer
Rc<T>
can’t be used in a multithreading environment# as it doesn’t implement the 202204061235# 202207172159# and 202207172210#. -
Mutex in Rust
As you can see that, we wrap around the Mutex into another type,
Arc
(imported fromstd::sync::Arc
). It allows the data to be shared across multiple threads without violating the rule of Rust ownership, that is, it is atomic. You can treat it as 202206221720# with the 202207172159# and 202207172210# 202204061235#.