Skip to main content

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

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