| 1 |
use std::sync::atomic::AtomicU8; |
| 2 |
use std::sync::atomic::Ordering; |
| 3 |
|
| 4 |
use blanket::blanket; |
| 5 |
use impls::impls; |
| 6 |
|
| 7 |
#[blanket(derive(Mut))] |
| 8 |
pub trait Counter { |
| 9 |
type Return: Clone; |
| 10 |
fn increment(&mut self) -> Self::Return; |
| 11 |
} |
| 12 |
|
| 13 |
#[derive(Default)] |
| 14 |
struct AtomicCounter { |
| 15 |
count: AtomicU8, |
| 16 |
} |
| 17 |
|
| 18 |
impl Counter for AtomicCounter { |
| 19 |
|
| 20 |
type Return = u8; |
| 21 |
fn increment(&mut self) -> u8 { |
| 22 |
self.count.fetch_add(1, Ordering::SeqCst) |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
fn main() { |
| 27 |
assert!(impls!(AtomicCounter: Counter)); |
| 28 |
assert!(impls!(&mut AtomicCounter: Counter)); |
| 29 |
} |