October 2018
Beginner
180 pages
4h 48m
English
The Sync trait is automatically applied to any data type that can safely be borrowed between threads.
While our data types will have the Sync trait automatically if they qualify for it, occasionally we want to be sure that a data type does not have Sync, even if it looks to the compiler like it should.
We can achieve that by implementing !Sync for our data type:
pub enum NotSyncExample { Good, Bad,}impl !Sync for NotSyncExample {}
We don't actually need any functions inside of !Sync. All we're doing is telling the compiler that the Sync trait is inappropriate for this type.
Read now
Unlock full access