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 StateData.retain(|_, Value| Validator(Value));
14 let RemovedCount = OriginalLen - StateData.len();
15
16 if RemovedCount > 0 {
17 dev_log!(
18 "lifecycle",
19 "warn: [RecoverState] Removed {} invalid state entries ({} remaining)",
20 RemovedCount,
21 StateData.len()
22 );
23 }
24}