use std::sync::{atomic::AtomicUsize, Arc};
#[derive(Debug, Clone)]
pub struct Attempt(Arc<AtomicUsize>);
impl Default for Attempt {
fn default() -> Self {
Self(Arc::new(AtomicUsize::new(0)))
}
}
impl Attempt {
pub fn new() -> Self {
Self::default()
}
pub fn new_with_value(value: usize) -> Self {
Self(Arc::new(AtomicUsize::from(value)))
}
pub fn current(&self) -> usize {
self.0.load(std::sync::atomic::Ordering::Relaxed)
}
pub fn increment(&self) -> usize {
self.0.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
}
}