From 8d9dc830476170d01f94fe4dc6967b3d4ecdbab0 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Wed, 4 Jan 2023 11:50:52 +0100 Subject: refactor: Deserialize into struct directly (#127) Instead of deserializing into a generic serde struct and then extracting specific value from it, deserialize directly into the struct we want. --- src-tauri/src/github/release_notes.rs | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) (limited to 'src-tauri') diff --git a/src-tauri/src/github/release_notes.rs b/src-tauri/src/github/release_notes.rs index f139ead5..803132e2 100644 --- a/src-tauri/src/github/release_notes.rs +++ b/src-tauri/src/github/release_notes.rs @@ -91,28 +91,9 @@ pub async fn get_northstar_release_notes() -> Result, String> { let url = "https://api.github.com/repos/R2Northstar/Northstar/releases"; let res = fetch_github_releases_api(url).await?; - let json_response: Vec = + let release_info_vector: Vec = serde_json::from_str(&res).expect("JSON was not well-formatted"); println!("Done checking GitHub API"); - return Ok(json_response - .iter() - .map(|release| ReleaseInfo { - name: release - .get("name") - .and_then(|value| value.as_str()) - .unwrap() - .to_string(), - published_at: release - .get("published_at") - .and_then(|value| value.as_str()) - .unwrap() - .to_string(), - body: release - .get("body") - .and_then(|value| value.as_str()) - .unwrap() - .to_string(), - }) - .collect()); + return Ok(release_info_vector); } -- cgit v1.2.3