diff options
| author | Nathan Jaremko | 2017-11-30 10:04:32 -0500 |
|---|---|---|
| committer | Nathan Jaremko | 2017-11-30 10:04:32 -0500 |
| commit | 6eba4ba3ac9bed6c6b89a2ba8286093a8febf103 (patch) | |
| tree | 7fbd4385b906cc4bc2f7f3069f8a6f3fa5c8ed86 | |
| parent | 752190225f31f559cb4288442755b7c0868f5b27 (diff) | |
| download | podcast-6eba4ba3ac9bed6c6b89a2ba8286093a8febf103.tar.bz2 | |
Change order in State struct
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/structs.rs | 11 |
2 files changed, 7 insertions, 6 deletions
@@ -1,6 +1,6 @@ [package] name = "podcast" -version = "0.4.1" +version = "0.4.2" authors = ["njaremko <njaremko@gmail.com>"] description = "A command line podcast player" license = "GPL-3.0" diff --git a/src/structs.rs b/src/structs.rs index be5c6d5..e9b8c28 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -55,9 +55,9 @@ pub struct Subscription { #[derive(Serialize, Deserialize, Clone)] pub struct State { + pub version: String, pub last_run_time: DateTime<Utc>, pub subscriptions: Vec<Subscription>, - pub version: String, } impl State { @@ -75,19 +75,20 @@ impl State { }; let mut state: State = match serde_json::from_str(&s) { Ok(val) => val, + // This will happen if the struct has changed between versions Err(_) => { let v: serde_json::Value = serde_json::from_str(&s).unwrap(); State { + version: String::from(version), last_run_time: Utc::now(), subscriptions: match serde_json::from_value(v["subscriptions"].clone()) { Ok(val) => val, Err(_) => serde_json::from_value(v["subs"].clone()).unwrap(), - }, - version: String::from(version), + }, } } }; - // Check if a day has passed (86400 seconds) + // Check if a day has passed (86400 seconds) since last launch if state .last_run_time .signed_duration_since(Utc::now()) @@ -100,9 +101,9 @@ impl State { Ok(state) } else { Ok(State { + version: String::from(version), last_run_time: Utc::now(), subscriptions: Vec::new(), - version: String::from(version), }) } } |
