use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct RecordingState {
pub active: Arc<AtomicBool>,
}
impl RecordingState {
pub fn new(initially_active: bool) -> Self {
Self {
active: Arc::new(AtomicBool::new(initially_active)),
}
}
pub fn set_active(&self, active: bool) {
self.active.store(active, Ordering::SeqCst);
}
pub fn is_active(&self) -> bool {
self.active.load(Ordering::SeqCst)
}
pub fn toggle(&self) -> bool {
let previous = self.active.fetch_xor(true, Ordering::SeqCst);
!previous
}
}