MCPcopy Index your code
hub / github.com/encounter/objdiff / deserialize_config

Function deserialize_config

objdiff-gui/src/app_config.rs:26–44  ·  view source on GitHub ↗

Deserialize the AppConfig from storage, handling upgrades from older versions.

(storage: &dyn Storage)

Source from the content-addressed store, hash-verified

24
25/// Deserialize the AppConfig from storage, handling upgrades from older versions.
26pub fn deserialize_config(storage: &dyn Storage) -> Option<AppConfig> {
27 let str = storage.get_string(CONFIG_KEY)?;
28 match ron::from_str::<AppConfigVersion>(&str) {
29 Ok(version) => match version.version {
30 3 => from_str::<AppConfig>(&str),
31 2 => from_str::<AppConfigV2>(&str).map(|c| c.into_config()),
32 1 => from_str::<AppConfigV1>(&str).map(|c| c.into_config()),
33 _ => {
34 log::warn!("Unknown config version: {}", version.version);
35 None
36 }
37 },
38 Err(e) => {
39 log::warn!("Failed to decode config version: {e}");
40 // Try to decode as v0
41 from_str::<AppConfigV0>(&str).map(|c| c.into_config())
42 }
43 }
44}
45
46fn from_str<T>(str: &str) -> Option<T>
47where T: serde::de::DeserializeOwned {

Callers 1

newMethod · 0.85

Calls 1

into_configMethod · 0.80

Tested by

no test coverage detected