1#![allow(clippy::module_inception)]
2
3mod mask;
4mod mask_impl;
5
6pub use mask::*;
7
8use once_cell::sync::Lazy;
9use std::{collections::HashSet, sync::Mutex};
10
11use crate::Uuid;
12
13static MASKS_ALIVE: Lazy<Mutex<HashSet<Uuid>>> =
15 Lazy::new(|| Mutex::new(HashSet::with_capacity(294)));
16
17fn exec<F, R>(f: F) -> R
18where
19 F: FnOnce(&mut HashSet<Uuid>) -> R,
20{
21 f(&mut MASKS_ALIVE.lock().unwrap())
22}
23
24pub(super) fn alive_add(uuid: &Uuid) {
25 exec(|list| {
26 list.insert(uuid.to_owned());
27 });
28}
29
30pub(super) fn alive_remove(uuid: &Uuid) {
31 exec(|list| {
32 list.remove(uuid);
33 });
34}
35
36pub fn is_alive(uuid: &Uuid) -> bool {
37 exec(|list| list.contains(uuid))
38}
39
40pub fn alive_len() -> usize {
41 exec(|list| list.len())
42}
43
44pub fn alive_collect<B>() -> B
45where
46 B: FromIterator<Uuid>,
47{
48 exec(|list| list.iter().cloned().collect())
49}