From 34f1c6229bac92212c97cbacc77801d4a2921e4a Mon Sep 17 00:00:00 2001 From: Vika Date: Tue, 10 May 2022 21:08:44 +0300 Subject: database, frontend: code cleanup so clippy doesn't complain --- src/database/memory.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'src/database/memory.rs') diff --git a/src/database/memory.rs b/src/database/memory.rs index 5e2ad52..786466c 100644 --- a/src/database/memory.rs +++ b/src/database/memory.rs @@ -43,11 +43,10 @@ impl Storage for MemoryStorage { async fn put_post(&self, post: &'_ serde_json::Value, _user: &'_ str) -> Result<()> { let mapping = &mut self.mapping.write().await; - let key: &str; - match post["properties"]["uid"][0].as_str() { - Some(uid) => key = uid, + let key: &str = match post["properties"]["uid"][0].as_str() { + Some(uid) => uid, None => return Err(StorageError::new(ErrorKind::Other, "post doesn't have a UID")) - } + }; mapping.insert(key.to_string(), post.clone()); if post["properties"]["url"].is_array() { for url in post["properties"]["url"].as_array().unwrap().iter().map(|i| i.as_str().unwrap().to_string()) { @@ -110,12 +109,11 @@ impl Storage for MemoryStorage { } for (k, v) in remove_values { let k = &k; - let props; - if k == "children" { - props = &mut post; + let props = if k == "children" { + &mut post } else { - props = &mut post["properties"]; - } + &mut post["properties"] + }; v.iter().for_each(|v| { if let Some(vec) = props[k].as_array_mut() { if let Some(index) = vec.iter().position(|w| w == v) { @@ -125,12 +123,11 @@ impl Storage for MemoryStorage { }); } for (k, v) in add_keys { - let props; - if k == "children" { - props = &mut post; + let props = if k == "children" { + &mut post } else { - props = &mut post["properties"]; - } + &mut post["properties"] + }; let k = &k; if let Some(prop) = props[k].as_array_mut() { if k == "children" { -- cgit 1.4.1