use std::cell::Cell;
thread_local! { static LIMITS: Cell<(Option<usize>, Option<u64>)> = const { Cell::new((None, None)) }; }
#[cfg(test)]
pub(crate) struct Guard((Option<usize>, Option<u64>));
#[cfg(test)]
impl Drop for Guard {
fn drop(&mut self) {
LIMITS.with(|limits| limits.set(self.0));
}
}
#[cfg(test)]
pub(crate) fn install(storage: Option<usize>, work: Option<u64>) -> Guard {
Guard(LIMITS.with(|limits| limits.replace((storage, work))))
}
pub(crate) fn limits(storage: usize, work: u64) -> (usize, u64) {
LIMITS.with(|limits| {
let (bytes, units) = limits.get();
(bytes.unwrap_or(storage), units.unwrap_or(work))
})
}