use std::sync::RwLock;
use crate::config::LimitsConfig;
static LIMITS: RwLock<LimitsConfig> = RwLock::new(LimitsConfig::DEFAULT);
pub fn get() -> LimitsConfig {
*LIMITS.read().unwrap_or_else(|e| e.into_inner())
}
pub fn set(limits: LimitsConfig) {
*LIMITS.write().unwrap_or_else(|e| e.into_inner()) = limits;
}
pub(crate) fn left_out(left: &str, limit: usize, key: &str) -> String {
format!(
"{left} left out: past the first {} {} limits.{key} raises it",
crate::numfmt::group_chrome(limit),
crate::glyphs::get().middot
)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_left_out_note_names_its_key() {
let note = left_out("3 records", 64 << 20, "indexed_records");
assert!(note.starts_with("3 records left out: past the first 67,108,864"));
assert!(note.ends_with("limits.indexed_records raises it"), "{note}");
}
#[test]
fn the_section_reads_from_toml() {
let limits: LimitsConfig =
toml::from_str("elf_symbols = 5\nmidi_bytes = \"1MiB\"").unwrap();
assert_eq!(limits.elf_symbols, 5);
assert_eq!(limits.midi_bytes.bytes(), 1 << 20);
assert_eq!(
limits.indexed_records,
LimitsConfig::DEFAULT.indexed_records
);
}
}