3 ms·
I really liked this article, but if I can provide some sort of drive-by advice (also for others looking to write technical content), providing some examples of
by singhrac 4y ago
I really liked this article, but if I can provide some sort of drive-by advice (also for others looking to write technical content), providing some examples of where to use various traits would really help, e.g. what kind of data structure one would implement !Send on.
- drogus 4y agoThat's a good point and I think I will add a paragraph or too about that. The simplest answer is: as long as you're not doing any unsafe Rust you should just use whatever is derived from types within a type. If you have a struct where all fields are `Send`, then the struct will be `Send` too. If you add anything that is `!Send` (like `Cell`), it will be `!Send` and you don't have to explicitly mark is as `!Send`. The most common exception to this is when you implement a type that has a `!Send` attribute, but you still mark it as `Send`, because you implement an API that guards against misusing the type. I honestly can't think of any practical example of the opposite (ie. you have a type with all `Send` attributes), but that would probably be similar: you have a type with all `Send` attributes, but you implement some kind of API that makes it unsafe to sent the type between threads.