/rust/registry/src/index.crates.io-1949cf8c6b5b557f/snafu-0.9.0/src/once_bool.rs
Line | Count | Source |
1 | | use std::sync::{ |
2 | | atomic::{AtomicBool, Ordering}, |
3 | | Once, |
4 | | }; |
5 | | |
6 | | pub struct OnceBool { |
7 | | start: Once, |
8 | | enabled: AtomicBool, |
9 | | } |
10 | | |
11 | | impl OnceBool { |
12 | 0 | pub const fn new() -> Self { |
13 | 0 | Self { |
14 | 0 | start: Once::new(), |
15 | 0 | enabled: AtomicBool::new(false), |
16 | 0 | } |
17 | 0 | } |
18 | | |
19 | 0 | pub fn get<F: FnOnce() -> bool>(&self, f: F) -> bool { |
20 | 0 | self.start.call_once(|| { |
21 | 0 | let enabled = f(); |
22 | 0 | self.enabled.store(enabled, Ordering::SeqCst); |
23 | 0 | }); Unexecuted instantiation: <snafu::once_bool::OnceBool>::get::<snafu::backtrace_collection_enabled::{closure#0}>::{closure#0}Unexecuted instantiation: <snafu::once_bool::OnceBool>::get::<snafu::report::trace_cleaning_enabled::{closure#0}>::{closure#0} |
24 | | |
25 | 0 | self.enabled.load(Ordering::SeqCst) |
26 | 0 | } Unexecuted instantiation: <snafu::once_bool::OnceBool>::get::<snafu::backtrace_collection_enabled::{closure#0}>Unexecuted instantiation: <snafu::once_bool::OnceBool>::get::<snafu::report::trace_cleaning_enabled::{closure#0}> |
27 | | } |