Understanding the Send and Sync traits

The secret ingredients for this to work are the Send and Sync traits. They are traits known to the compiler, so it will check whether they are the types we use want to use to implement them and act accordingly. You cannot implement Send or Sync for your types directly. The compiler will know whether your types are Send or Sync by checking whether the contained fields are Sync or Send, in the case of structures or enumerations with fields.

Let's now understand how they work. First of all, you should note that neither Send nor Sync traits add methods to a given type. This means that, once compiled, they will not occupy any memory or add any extra overhead to your binary. They will only be checked at compile time to make sure that multithreading is safe. You cannot directly implement Send or Sync for your types unless you are using an unsafe block, so the compiler will do it for you where appropriate.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.22.179