| 1 | extern crate blanket; |
| 2 | extern crate impls; |
| 3 | |
| 4 | use std::rc::Rc; |
| 5 | use std::sync::atomic::AtomicU8; |
| 6 | use std::sync::atomic::Ordering; |
| 7 | |
| 8 | use blanket::blanket; |
| 9 | use impls::impls; |
| 10 | |
| 11 | #[blanket(derive(Rc))] |
| 12 | pub trait Counter<T> |
| 13 | where |
| 14 | T: Clone, |
| 15 | { |
| 16 | fn increment(&self, t: T); |
| 17 | |
| 18 | fn super_helpful_helper(&self, t: T) |
| 19 | { |
| 20 | self.increment(t.clone()) |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | struct AtomicCounter { |
| 25 | count: AtomicU8, |
| 26 | } |
| 27 | |
| 28 | impl Counter<u8> for AtomicCounter { |
| 29 | fn increment(&self, value: u8) { |
| 30 | self.count.fetch_add(value, Ordering::SeqCst); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | fn main() { |
| 35 | assert!(impls!(AtomicCounter: Counter<u8>)); |
| 36 | assert!(impls!(Rc<AtomicCounter>: Counter<u8>)); |
| 37 | } |