1 use std::sync::Arc; 2 use std::sync::atomic::AtomicU8; 3 use std::sync::atomic::Ordering; 4 5 use blanket::blanket; 6 use impls::impls; 7 8 #[blanket(derive(Arc))] 9 pub trait Counter { 10 type Return: Clone; // <- verify this increment(&self) -> Self::Return11 fn increment(&self) -> Self::Return; 12 } 13 14 #[derive(Default)] 15 struct AtomicCounter { 16 count: AtomicU8, 17 } 18 19 impl Counter for AtomicCounter { 20 // Generate something like `type Return = <A as Assoc>::Return;`. 21 type Return = u8; increment(&self) -> u822 fn increment(&self) -> u8 { 23 self.count.fetch_add(1, Ordering::SeqCst) 24 } 25 } 26 main()27fn main() { 28 assert!(impls!(AtomicCounter: Counter)); 29 assert!(impls!(Arc<AtomicCounter>: Counter)); 30 } 31