use core::borrow::Borrow; use core::borrow::BorrowMut; use std::sync::Arc; #[derive(Debug, Clone, Default)] pub struct Counter(Arc<()>, Arc<()>); #[derive(Debug)] pub struct Item(Arc<()>, T); impl Counter { pub fn new() -> Self { Default::default() } pub fn count(&self) -> usize { Arc::strong_count(&self.0) - Arc::strong_count(&self.1) } pub fn add(&self, value: T) -> Item { Item(Arc::clone(&self.0), value) } } impl Borrow for Item { fn borrow(&self) -> &T { &self.1 } } impl BorrowMut for Item { fn borrow_mut(&mut self) -> &mut T { &mut self.1 } } impl PartialEq for Item where T: PartialEq, { fn eq(&self, other: &T) -> bool { self.1.eq(other) } }