Skip to main content

deserialize_with_fallback

Function deserialize_with_fallback 

Source
fn deserialize_with_fallback<'de, D, T>(
    deserializer: D,
    field: &str,
    parse: fn(&str) -> Option<T>,
) -> T
where D: Deserializer<'de>, T: Default,
Expand description

Deserialise a lowercase-tagged enum permissively: read the raw string and map it through parse, falling back to T::default() with a single logged warning on any unknown/corrupt value.

This preserves the pre-enum runtime behaviour exactly — the old String fields stored arbitrary text and the *_for matchers silently treated anything unrecognised as the fallback. Keeping that here means a hand-edited or stale settings.json still loads instead of having serde reject the whole profile. We can’t lean on the derived Deserialize for the strict parse (it would recurse back into this custom impl), so each enum hands in its own from_disk_str.