How to enforce that a type implements a trait at compile time?
First, solve the problem without macros. One solution is to create undocumented private functions that will fail compilation if your conditions aren’t met: struct MyType { age: i32, name: String, } const _: () = { fn assert_send<T: Send>() {} fn assert_sync<T: Sync>() {} // RFC 2056 fn assert_all() { assert_send::<MyType>(); assert_sync::<MyType>(); } }; Then, … Read more