Skip to main content

runmat_runtime/
warning_store.rs

1use once_cell::sync::Lazy;
2use std::sync::Mutex;
3
4#[derive(Clone, Debug)]
5pub struct RuntimeWarning {
6    pub identifier: String,
7    pub message: String,
8}
9
10static WARNINGS: Lazy<Mutex<Vec<RuntimeWarning>>> = Lazy::new(|| Mutex::new(Vec::new()));
11
12pub fn push(identifier: &str, message: &str) {
13    if let Ok(mut guard) = WARNINGS.lock() {
14        guard.push(RuntimeWarning {
15            identifier: identifier.to_string(),
16            message: message.to_string(),
17        });
18    }
19}
20
21pub fn take_all() -> Vec<RuntimeWarning> {
22    WARNINGS
23        .lock()
24        .map(|mut guard| guard.drain(..).collect())
25        .unwrap_or_default()
26}
27
28pub fn reset() {
29    if let Ok(mut guard) = WARNINGS.lock() {
30        guard.clear();
31    }
32}