1use std::sync::RwLock;
5
6use crate::config::LimitsConfig;
7
8static LIMITS: RwLock<LimitsConfig> = RwLock::new(LimitsConfig::DEFAULT);
9
10pub fn get() -> LimitsConfig {
12 *LIMITS.read().unwrap_or_else(|e| e.into_inner())
13}
14
15pub fn set(limits: LimitsConfig) {
17 *LIMITS.write().unwrap_or_else(|e| e.into_inner()) = limits;
18}
19
20pub(crate) fn left_out(left: &str, limit: usize, key: &str) -> String {
23 format!(
24 "{left} left out: past the first {} {} limits.{key} raises it",
25 crate::numfmt::group_chrome(limit),
26 crate::glyphs::get().middot
27 )
28}
29
30#[cfg(test)]
31mod tests {
32 use super::*;
33
34 #[test]
36 fn a_left_out_note_names_its_key() {
37 let note = left_out("3 records", 64 << 20, "indexed_records");
38 assert!(note.starts_with("3 records left out: past the first 67,108,864"));
39 assert!(note.ends_with("limits.indexed_records raises it"), "{note}");
40 }
41
42 #[test]
44 fn the_section_reads_from_toml() {
45 let limits: LimitsConfig =
46 toml::from_str("elf_symbols = 5\nmidi_bytes = \"1MiB\"").unwrap();
47 assert_eq!(limits.elf_symbols, 5);
48 assert_eq!(limits.midi_bytes.bytes(), 1 << 20);
49 assert_eq!(
50 limits.indexed_records,
51 LimitsConfig::DEFAULT.indexed_records
52 );
53 }
54}