Properly cfg the max field of Limit

This commit is contained in:
Lukas Wirth 2022-07-31 19:27:20 +02:00
parent ec3586eab9
commit d31f3605ce

View File

@ -2,12 +2,13 @@
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] #![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
#[cfg(feature = "tracking")]
use std::sync::atomic::AtomicUsize; use std::sync::atomic::AtomicUsize;
/// Represents a struct used to enforce a numerical limit. /// Represents a struct used to enforce a numerical limit.
pub struct Limit { pub struct Limit {
upper_bound: usize, upper_bound: usize,
#[allow(unused)] #[cfg(feature = "tracking")]
max: AtomicUsize, max: AtomicUsize,
} }
@ -15,14 +16,22 @@ impl Limit {
/// Creates a new limit. /// Creates a new limit.
#[inline] #[inline]
pub const fn new(upper_bound: usize) -> Self { pub const fn new(upper_bound: usize) -> Self {
Self { upper_bound, max: AtomicUsize::new(0) } Self {
upper_bound,
#[cfg(feature = "tracking")]
max: AtomicUsize::new(0),
}
} }
/// Creates a new limit. /// Creates a new limit.
#[inline] #[inline]
#[cfg(feature = "tracking")] #[cfg(feature = "tracking")]
pub const fn new_tracking(upper_bound: usize) -> Self { pub const fn new_tracking(upper_bound: usize) -> Self {
Self { upper_bound, max: AtomicUsize::new(1) } Self {
upper_bound,
#[cfg(feature = "tracking")]
max: AtomicUsize::new(1),
}
} }
/// Gets the underlying numeric limit. /// Gets the underlying numeric limit.