snafu/once_bool.rs
1use std::sync::{
2 atomic::{AtomicBool, Ordering},
3 Once,
4};
5
6pub struct OnceBool {
7 start: Once,
8 enabled: AtomicBool,
9}
10
11impl OnceBool {
12 pub const fn new() -> Self {
13 Self {
14 start: Once::new(),
15 enabled: AtomicBool::new(false),
16 }
17 }
18
19 pub fn get<F: FnOnce() -> bool>(&self, f: F) -> bool {
20 self.start.call_once(|| {
21 let enabled = f();
22 self.enabled.store(enabled, Ordering::SeqCst);
23 });
24
25 self.enabled.load(Ordering::SeqCst)
26 }
27}