1#![doc = include_str!("../README.md")]
2#![cfg_attr(not(feature = "std"), no_std)]
3
4#[cfg(feature = "std")]
5use std::sync::{Arc, Weak};
6
7#[cfg(not(feature = "std"))]
8extern crate alloc;
9
10#[cfg(not(feature = "std"))]
11use alloc::sync::{Arc, Weak};
12
13#[derive(Clone)]
15pub struct Counter(Arc<()>);
16
17#[derive(Clone)]
19pub struct Register(Weak<()>);
20
21impl Counter {
22 pub fn new() -> Self {
24 Self(Arc::new(()))
25 }
26
27 pub fn reg(&self) -> Register {
29 Register(Arc::downgrade(&self.0))
30 }
31
32 pub fn count(&self) -> usize {
34 Arc::weak_count(&self.0)
35 }
36}