about summary refs log tree commit diff
path: root/src/database/memory.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/database/memory.rs')
-rw-r--r--src/database/memory.rs25
1 files changed, 11 insertions, 14 deletions
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" {