From b3cec1a3832a4663635c873a700fbb4cc1089108 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Mon, 11 Apr 2022 16:12:56 -0700 Subject: [PATCH] Prefer using direct method calls instead of using the json macros --- flatten-serde-json/src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/flatten-serde-json/src/lib.rs b/flatten-serde-json/src/lib.rs index 734ae2a24..8312f5bd6 100644 --- a/flatten-serde-json/src/lib.rs +++ b/flatten-serde-json/src/lib.rs @@ -1,6 +1,6 @@ #![doc = include_str!("../README.md")] -use serde_json::{json, Map, Value}; +use serde_json::{Map, Value}; pub fn flatten(json: &Map) -> Map { let mut obj = Map::new(); @@ -42,7 +42,7 @@ fn insert_value(base_json: &mut Map, key: &str, to_insert: Value) debug_assert!(!to_insert.is_object()); debug_assert!(!to_insert.is_array()); - // does the field aleardy exists? + // does the field already exists? if let Some(value) = base_json.get_mut(key) { // is it already an array if let Some(array) = value.as_array_mut() { @@ -50,16 +50,18 @@ fn insert_value(base_json: &mut Map, key: &str, to_insert: Value) // or is there a collision } else { let value = std::mem::take(value); - base_json[key] = json!([value, to_insert]); + base_json[key] = Value::Array(vec![value, to_insert]); } // if it does not exist we can push the value untouched } else { - base_json.insert(key.to_string(), json!(to_insert)); + base_json.insert(key.to_string(), to_insert); } } #[cfg(test)] mod tests { + use serde_json::json; + use super::*; #[test]