Skip to main content

Mountain/ApplicationState/Internal/Recovery/RecoverState/
ValidateAndCleanState.rs

1#![allow(non_snake_case)]
2
3//! Filter a state map in-place by a validator predicate. Logs at warn
4//! level when entries are removed so corruption is visible without
5//! drowning the recovery path in chatter when nothing changes.
6
7use std::collections::HashMap;
8
9use crate::dev_log;
10
11pub fn Fn<T>(StateData:&mut HashMap<String, T>, Validator:impl Fn(&T) -> bool) {
12	let OriginalLen = StateData.len();
13
14	StateData.retain(|_, Value| Validator(Value));
15
16	let RemovedCount = OriginalLen - StateData.len();
17
18	if RemovedCount > 0 {
19		dev_log!(
20			"lifecycle",
21			"warn: [RecoverState] Removed {} invalid state entries ({} remaining)",
22			RemovedCount,
23			StateData.len()
24		);
25	}
26}