Common traits and their priority:
Debug- every type should implement itSendandSync- implement unless there is a specific reason not to. NoSendmeans the type can’t be sent to another thread (no thread pools, noMutex<T>). NoSyncmeans a shared reference to the type can’t be sent across threads (noArc<T>orstatic)CloneandDefault- must implementPartialEq,PartialOrd,Hash,EqandOrd- where possible implement them, especiallyPartialEqandPartialOrdSerializeandDeserialize- most libraries choose to provide aserdefeature flag to not force a dependency
See also
- Principle of Least Astonishment - implementing standard traits is a Least Astonishment expectation
- &T Is a Shared Reference, Copy but Not Mutable -
Syncis the thread-safety equivalent of&T.TisSyncif and only if&TisSend - Interior Mutability Allows Mutation Through &T, Either by Runtime-Checked Exclusivity or In-Place Methods - types with interior mutability are not
Syncbecause shared references could race - Interface Segregation Principle (ISP) - the
serdefeature flag pattern is ISP applied to Rust crates: don’t force aserdedependency on callers who don’t need serialisation
References
- J. Gjengset, Rust for Rustaceans: Idiomatic Programming for Experienced Developers. No Starch Press, 2021.