| 1 |
use std::rc::Rc; |
| 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(Rc))] |
| 9 |
pub trait Counter { |
| 10 |
type Return: Clone; |
| 11 |
fn increment(&self) -> Self::Return; |
| 12 |
} |
| 13 |
|
| 14 |
#[derive(Default)] |
| 15 |
struct AtomicCounter { |
| 16 |
count: AtomicU8, |
| 17 |
} |
| 18 |
|
| 19 |
impl Counter for AtomicCounter { |
| 20 |
|
| 21 |
type Return = u8; |
| 22 |
fn increment(&self) -> u8 { |
| 23 |
self.count.fetch_add(1, Ordering::SeqCst) |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
fn main() { |
| 28 |
assert!(impls!(AtomicCounter: Counter)); |
| 29 |
assert!(impls!(Rc<AtomicCounter>: Counter)); |
| 30 |
} |