diff --git a/Cargo.toml b/Cargo.toml index fe49cf6..1ea05db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "json" -version = "0.12.2" +version = "0.12.3" authors = ["Maciej Hirsz "] description = "JSON implementation in Rust" repository = "https://github.com/maciejhirsz/json-rust" diff --git a/README.md b/README.md index af7626c..0fac515 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ -# json-rust +![](https://raw.githubusercontent.com/maciejhirsz/json-rust/master/json-rust-logo-small.png) -[![Travis shield](https://travis-ci.org/maciejhirsz/json-rust.svg)](https://travis-ci.org/maciejhirsz/json-rust) -[![Crates.io version shield](https://img.shields.io/crates/v/json.svg)](https://crates.io/crates/json) -[![Crates.io license shield](https://img.shields.io/crates/l/json.svg)](https://crates.io/crates/json) +# json-rust Parse and serialize [JSON](http://json.org/) with ease. @@ -11,7 +9,6 @@ Parse and serialize [JSON](http://json.org/) with ease. **[Cargo](https://crates.io/crates/json) -** **[Repository](https://github.com/maciejhirsz/json-rust)** - ## Why? JSON is a very loose format where anything goes - arrays can hold mixed @@ -39,10 +36,11 @@ let parsed = json::parse(r#" "#).unwrap(); let instantiated = object!{ - "code" => 200, - "success" => true, - "payload" => object!{ - "features" => array![ + // quotes on keys are optional + "code": 200, + success: true, + payload: { + features: [ "awesome", "easyAPI", "lowLearningCurve" @@ -59,10 +57,10 @@ Using macros and indexing, it's easy to work with the data. ```rust let mut data = object!{ - "foo" => false, - "bar" => json::Null, - "answer" => 42, - "list" => array![json::Null, "world", true] + foo: false, + bar: null, + answer: 42, + list: [null, "world", true] }; // Partial equality is implemented for most raw types: diff --git a/json-rust-logo-small.png b/json-rust-logo-small.png new file mode 100644 index 0000000..c1e6a66 Binary files /dev/null and b/json-rust-logo-small.png differ diff --git a/src/lib.rs b/src/lib.rs index d4bab94..40f6869 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -//! ![](http://terhix.com/doc/json-rust-logo-small.png) +//! ![](https://raw.githubusercontent.com/maciejhirsz/json-rust/master/json-rust-logo-small.png) //! //! # json-rust //! @@ -38,10 +38,11 @@ //! "#).unwrap(); //! //! let instantiated = object!{ -//! "code" => 200, -//! "success" => true, -//! "payload" => object!{ -//! "features" => array![ +//! // quotes on keys are optional +//! "code": 200, +//! success: true, +//! payload: { +//! features: [ //! "awesome", //! "easyAPI", //! "lowLearningCurve" @@ -61,10 +62,10 @@ //! # #[macro_use] extern crate json; //! # fn main() { //! let mut data = object!{ -//! "foo" => false, -//! "bar" => json::Null, -//! "answer" => 42, -//! "list" => array![json::Null, "world", true] +//! foo: false, +//! bar: null, +//! answer: 42, +//! list: [null, "world", true] //! }; //! //! // Partial equality is implemented for most raw types: @@ -174,7 +175,7 @@ //! ``` //! # #[macro_use] extern crate json; //! # fn main() { -//! let data = array!["foo", "bar", 100, true, json::Null]; +//! let data = array!["foo", "bar", 100, true, null]; //! assert_eq!(data.dump(), r#"["foo","bar",100,true,null]"#); //! # } //! ``` @@ -185,9 +186,9 @@ //! # #[macro_use] extern crate json; //! # fn main() { //! let data = object!{ -//! "name" => "John Doe", -//! "age" => 30, -//! "canJSON" => true +//! name: "John Doe", +//! age: 30, +//! canJSON: true //! }; //! assert_eq!( //! data.dump(), @@ -279,16 +280,65 @@ pub fn stringify_pretty(root: T, spaces: u16) -> String where T: Into ($crate::JsonValue::new_array()); - [ $( $item:expr ),* ] => ({ - let size = 0 $( + {let _ = $item; 1} )*; + // Handles for token tree items + [@ITEM($( $i:expr, )*) $item:tt, $( $cont:tt )+] => { + $crate::array!( + @ITEM($( $i, )* $crate::value!($item), ) + $( $cont )* + ) + }; + (@ITEM($( $i:expr, )*) $item:tt,) => ({ + $crate::array!(@END $( $i, )* $crate::value!($item), ) + }); + (@ITEM($( $i:expr, )*) $item:tt) => ({ + $crate::array!(@END $( $i, )* $crate::value!($item), ) + }); + + // Handles for expression items + [@ITEM($( $i:expr, )*) $item:expr, $( $cont:tt )+] => { + $crate::array!( + @ITEM($( $i, )* $crate::value!($item), ) + $( $cont )* + ) + }; + (@ITEM($( $i:expr, )*) $item:expr,) => ({ + $crate::array!(@END $( $i, )* $crate::value!($item), ) + }); + (@ITEM($( $i:expr, )*) $item:expr) => ({ + $crate::array!(@END $( $i, )* $crate::value!($item), ) + }); + + // Construct the actual array + (@END $( $i:expr, )*) => ({ + let size = 0 $( + {let _ = || $i; 1} )*; let mut array = Vec::with_capacity(size); $( - array.push($item.into()); + array.push($i.into()); )* $crate::JsonValue::Array(array) - }) + }); + + // Entry point to the macro + ($( $cont:tt )+) => { + $crate::array!(@ITEM() $($cont)*) + }; +} + +#[macro_export] +/// Helper crate for converting types into `JsonValue`. It's used +/// internally by the `object!` and `array!` macros. +macro_rules! value { + ( null ) => { $crate::Null }; + ( [$( $token:tt )*] ) => { + // 10 + $crate::array![ $( $token )* ] + }; + ( {$( $token:tt )*} ) => { + $crate::object!{ $( $token )* } + }; + { $value:expr } => { $value }; } /// Helper macro for creating instances of `JsonValue::Object`. @@ -297,8 +347,8 @@ macro_rules! array { /// # #[macro_use] extern crate json; /// # fn main() { /// let data = object!{ -/// "foo" => 42, -/// "bar" => false +/// foo: 42, +/// bar: false, /// }; /// /// assert_eq!(data["foo"], 42); @@ -312,29 +362,68 @@ macro_rules! object { // Empty object. {} => ($crate::JsonValue::new_object()); - // Non-empty object, no trailing comma. - // - // In this implementation, key/value pairs separated by commas. - { $( $key:expr => $value:expr ),* } => { - $crate::object!( $( - $key => $value, - )* ) + // Handles for different types of keys + (@ENTRY($( $k:expr => $v:expr, )*) $key:ident: $( $cont:tt )*) => { + $crate::object!(@ENTRY($( $k => $v, )*) stringify!($key) => $($cont)*) }; + (@ENTRY($( $k:expr => $v:expr, )*) $key:literal: $( $cont:tt )*) => { + $crate::object!(@ENTRY($( $k => $v, )*) $key => $($cont)*) + }; + (@ENTRY($( $k:expr => $v:expr, )*) [$key:expr]: $( $cont:tt )*) => { + $crate::object!(@ENTRY($( $k => $v, )*) $key => $($cont)*) + }; + + // Handles for token tree values + (@ENTRY($( $k:expr => $v:expr, )*) $key:expr => $value:tt, $( $cont:tt )+) => { + $crate::object!( + @ENTRY($( $k => $v, )* $key => $crate::value!($value), ) + $( $cont )* + ) + }; + (@ENTRY($( $k:expr => $v:expr, )*) $key:expr => $value:tt,) => ({ + $crate::object!(@END $( $k => $v, )* $key => $crate::value!($value), ) + }); + (@ENTRY($( $k:expr => $v:expr, )*) $key:expr => $value:tt) => ({ + $crate::object!(@END $( $k => $v, )* $key => $crate::value!($value), ) + }); + + // Handles for expression values + (@ENTRY($( $k:expr => $v:expr, )*) $key:expr => $value:expr, $( $cont:tt )+) => { + $crate::object!( + @ENTRY($( $k => $v, )* $key => $crate::value!($value), ) + $( $cont )* + ) + }; + (@ENTRY($( $k:expr => $v:expr, )*) $key:expr => $value:expr,) => ({ + $crate::object!(@END $( $k => $v, )* $key => $crate::value!($value), ) + }); - // Non-empty object, trailing comma. - // - // In this implementation, the comma is part of the value. - { $( $key:expr => $value:expr, )* } => ({ - use $crate::object::Object; + (@ENTRY($( $k:expr => $v:expr, )*) $key:expr => $value:expr) => ({ + $crate::object!(@END $( $k => $v, )* $key => $crate::value!($value), ) + }); - let size = 0 $( + {let _ = $key; 1} )*; - let mut object = Object::with_capacity(size); + // Construct the actual object + (@END $( $k:expr => $v:expr, )*) => ({ + let size = 0 $( + {let _ = || $k; 1} )*; + let mut object = $crate::object::Object::with_capacity(size); $( - object.insert($key, $value.into()); + object.insert($k, $v.into()); )* $crate::JsonValue::Object(object) - }) -} + }); + + // Entry point to the macro + ($key:tt: $( $cont:tt )+) => { + $crate::object!(@ENTRY() $key: $($cont)*) + }; + // Legacy macro + ($( $k:expr => $v:expr, )*) => { + $crate::object!(@END $( $k => $crate::value!($v), )*) + }; + ($( $k:expr => $v:expr ),*) => { + $crate::object!(@END $( $k => $crate::value!($v), )*) + }; +} diff --git a/src/object.rs b/src/object.rs index bac50f1..7ff2165 100644 --- a/src/object.rs +++ b/src/object.rs @@ -654,7 +654,7 @@ impl<'a> ExactSizeIterator for IterMut<'a> { /// # /// # fn main() { /// let value = object!{ -/// "foo" => "bar" +/// foo: "bar" /// }; /// /// if let JsonValue::Object(object) = value { diff --git a/src/parser.rs b/src/parser.rs index 8209011..8fab0df 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -803,10 +803,10 @@ mod tests { let s = "{\"a\":1,\"b\":true,\"c\":false,\"d\":null,\"e\":2}"; let actual = parse(s).unwrap(); let mut expected = object! { - "a" => 1, - "b" => true, - "c" => false, - "e" => 2 + a: 1, + b: true, + c: false, + e: 2, }; expected["d"] = JsonValue::Null; @@ -818,18 +818,18 @@ mod tests { let s = "{\"a\":1,\"b\":true,\"c\":false,\"d\":null,\"e\":2,\"f\":[1,2,3,false,true,[],{}]}"; let actual = parse(s).unwrap(); let mut expected = object! { - "a" => 1, - "b" => true, - "c" => false, - "e" => 2 + a: 1, + b: true, + c: false, + e: 2, }; expected["d"] = JsonValue::Null; expected["f"] = array![ 1,2,3, false, true, - array![], - object!{} + [], + {}, ]; assert_eq!(actual, expected); @@ -840,22 +840,22 @@ mod tests { let s = "{\"a\":1,\"b\":{\"c\":2,\"d\":{\"e\":{\"f\":{\"g\":3,\"h\":[]}}},\"i\":4,\"j\":[],\"k\":{\"l\":5,\"m\":{}}}}"; let actual = parse(s).unwrap(); let expected = object! { - "a" => 1, - "b" => object!{ - "c" => 2, - "d" => object!{ - "e" => object! { - "f" => object!{ - "g" => 3, - "h" => array![] + a: 1, + b: { + c: 2, + d: { + e: { + f: { + g: 3, + h: [] } } }, - "i" => 4, - "j" => array![], - "k" => object!{ - "l" => 5, - "m" => object!{} + i: 4, + j: [], + k: { + l: 5, + m: {} } } }; @@ -868,25 +868,25 @@ mod tests { let s = "{\"a\":1,\"b\":{\"c\":2,\"d\":{\"e\":{\"f\":{\"g\":3,\"h\":[{\"z\":1},{\"y\":2,\"x\":[{},{}]}]}}},\"i\":4,\"j\":[],\"k\":{\"l\":5,\"m\":{}}}}"; let actual = parse(s).unwrap(); let expected = object! { - "a" => 1, - "b" => object!{ - "c" => 2, - "d" => object!{ - "e" => object! { - "f" => object!{ - "g" => 3, - "h" => array![ - object!{"z" => 1}, - object!{"y" => 2, "x" => array![object!{}, object!{}]} + a: 1, + b: { + c: 2, + d: { + e: { + f: { + g: 3, + h: [ + { z: 1 }, + { y: 2, x: [{}, {}]} ] } } }, - "i" => 4, - "j" => array![], - "k" => object!{ - "l" => 5, - "m" => object!{} + i: 4, + j: [], + k: { + l: 5, + m: {} } } }; diff --git a/src/value/mod.rs b/src/value/mod.rs index c30b7d0..ce2bfb3 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -604,7 +604,7 @@ impl IndexMut for JsonValue { /// # /// # fn main() { /// let object = object!{ -/// "foo" => "bar" +/// foo: "bar" /// }; /// /// assert!(object["foo"] == "bar"); diff --git a/tests/customgen.rs b/tests/customgen.rs index 43fa6cd..88df5ce 100644 --- a/tests/customgen.rs +++ b/tests/customgen.rs @@ -3,7 +3,7 @@ extern crate json; use json::codegen::Generator; use json::object::Object; -use json::{JsonValue, Null}; +use json::JsonValue; use std::io; /// Custom generator that sort keys by name; based on DumpGenerator. @@ -76,9 +76,9 @@ impl Generator for CustomGenerator { #[test] fn object_keys_sorted() { let o = object! { - "c" => Null, - "b" => Null, - "a" => Null, + c: null, + b: null, + a: null, }; let mut gen = CustomGenerator::new(); gen.write_json(&o).expect("Can't fail"); diff --git a/tests/parse.rs b/tests/parse.rs index 0fe2044..39cd06f 100644 --- a/tests/parse.rs +++ b/tests/parse.rs @@ -116,12 +116,12 @@ fn parse_array() { 10, "foo", true, - Null + null ]); assert_eq!(parse("[]").unwrap(), array![]); - assert_eq!(parse("[[]]").unwrap(), array![array![]]); + assert_eq!(parse("[[]]").unwrap(), array![[]]); } #[test] @@ -135,8 +135,8 @@ fn parse_object() { } "#).unwrap(), object!{ - "foo" => "bar", - "num" => 10 + foo: "bar", + num: 10 }); // Trailing comma in macro @@ -148,8 +148,8 @@ fn parse_object() { } "#).unwrap(), object!{ - "foo" => "bar", - "num" => 10, + foo: "bar", + num: 10, }); } @@ -164,8 +164,8 @@ fn parse_object_duplicate_fields() { } "#).unwrap(), object!{ - "foo" => 2, - "bar" => 1 + foo: 2, + bar: 1 }); } @@ -178,7 +178,7 @@ fn parse_object_with_array(){ } "#).unwrap(), object!{ - "foo" => array![1, 2, 3] + foo: [1, 2, 3] }); } @@ -197,10 +197,10 @@ fn parse_nested_object() { } "#).unwrap(), object!{ - "l10n" => array![ object!{ - "product" => object!{ - "inStock" => object!{ - "DE" => "Lieferung innerhalb von 1-3 Werktagen" + l10n: [ { + product: { + inStock: { + DE: "Lieferung innerhalb von 1-3 Werktagen" } } } ] diff --git a/tests/stringify.rs b/tests/stringify.rs index d2a8232..2a0abea 100644 --- a/tests/stringify.rs +++ b/tests/stringify.rs @@ -140,8 +140,8 @@ fn stringify_typed_opt_vec() { #[test] fn stringify_object() { let object = object!{ - "name" => "Maciej", - "age" => 30 + name: "Maciej", + age: 30 }; assert_eq!(object.dump(), r#"{"name":"Maciej","age":30}"#); @@ -183,8 +183,8 @@ fn stringify_hash_map() { let parsed = parse(&stringify(map)).unwrap(); assert_eq!(parsed, object!{ - "name" => "Maciej", - "age" => 30 + name: "Maciej", + age: 30 }); } @@ -234,13 +234,13 @@ fn stringify_control_escaped() { #[test] fn stringify_pretty_object() { let object = object!{ - "name" => "Urlich", - "age" => 50, - "parents" => object!{ - "mother" => "Helga", - "father" => "Brutus" + name: "Urlich", + age: 50, + parents: { + mother: "Helga", + father: "Brutus" }, - "cars" => array![ "Golf", "Mercedes", "Porsche" ] + cars: [ "Golf", "Mercedes", "Porsche" ] }; let expected = "{\n \"name\": \"Urlich\",\n \"age\": 50,\n \"parents\": {\n \"mother\": \"Helga\",\n \"father\": \"Brutus\"\n },\n \"cars\": [\n \"Golf\",\n \"Mercedes\",\n \"Porsche\"\n ]\n}"; diff --git a/tests/value.rs b/tests/value.rs index b8bbac6..736525b 100644 --- a/tests/value.rs +++ b/tests/value.rs @@ -49,7 +49,7 @@ fn is_as_number() { assert_eq!(number.as_i8(), None); assert_eq!(number.as_i16(), None); assert_eq!(number.as_i32(), Some(40_000)); - + let number = JsonValue::from(-5.5); assert_eq!(number.as_i8(), None); assert_eq!(number.as_i16(), None); @@ -124,7 +124,7 @@ fn is_empty() { assert!(!json::from("foo").is_empty()); assert!(!json::from(true).is_empty()); assert!(!array![0].is_empty()); - assert!(!object!{ "foo" => false }.is_empty()); + assert!(!object!{ foo: false }.is_empty()); } #[test] @@ -136,7 +136,7 @@ fn array_len() { #[test] fn array_contains() { - let data = array![true, Null, 3.14, "foo"]; + let data = array![true, null, 3.14, "foo"]; assert!(data.contains(true)); assert!(data.contains(Null)); @@ -207,7 +207,7 @@ fn array_members_rev() { #[test] fn array_members_mut() { - let mut data = array![Null, Null]; + let mut data = array![null, null]; for member in data.members_mut() { assert!(member.is_null()); @@ -219,7 +219,7 @@ fn array_members_mut() { #[test] fn array_members_mut_rev() { - let mut data = array![Null, Null]; + let mut data = array![null, null]; let mut item = 100; for member in data.members_mut().rev() { @@ -234,8 +234,8 @@ fn array_members_mut_rev() { #[test] fn object_len() { let data = object!{ - "a" => true, - "b" => false + a: true, + b: false }; assert_eq!(data.len(), 2); @@ -244,19 +244,19 @@ fn object_len() { #[test] fn object_remove() { let mut data = object!{ - "foo" => "bar", - "answer" => 42 + foo: "bar", + answer: 42 }; assert_eq!(data.remove("foo"), "bar"); - assert_eq!(data, object!{ "answer" => 42 }); + assert_eq!(data, object!{ answer: 42 }); } #[test] fn object_entries() { let data = object!{ - "a" => 1, - "b" => "foo" + a: 1, + b: "foo" }; for (_, value) in data.entries() { @@ -279,8 +279,8 @@ fn object_entries() { #[test] fn object_entries_rev() { let data = object!{ - "a" => 1, - "b" => "foo" + a: 1, + b: "foo" }; for (_, value) in data.entries().rev() { @@ -303,8 +303,8 @@ fn object_entries_rev() { #[test] fn object_entries_mut() { let mut data = object!{ - "a" => Null, - "b" => Null + a: null, + b: null }; for (_, value) in data.entries_mut() { @@ -313,16 +313,16 @@ fn object_entries_mut() { } assert_eq!(data, object!{ - "a" => 100, - "b" => 100 + a: 100, + b: 100 }); } #[test] fn object_entries_mut_rev() { let mut data = object!{ - "a" => Null, - "b" => Null + a: null, + b: null }; let mut item = 100; @@ -333,16 +333,16 @@ fn object_entries_mut_rev() { } assert_eq!(data, object!{ - "a" => item - 1, - "b" => item - 2 + a: item - 1, + b: item - 2 }); } #[test] fn object_dump_minified() { let object = object!{ - "name" => "Maciej", - "age" => 30 + name: "Maciej", + age: 30 }; assert_eq!(object.dump(), "{\"name\":\"Maciej\",\"age\":30}"); @@ -351,13 +351,13 @@ fn object_dump_minified() { #[test] fn object_dump_pretty() { let object = object!{ - "name" => "Urlich", - "age" => 50, - "parents" => object!{ - "mother" => "Helga", - "father" => "Brutus" + name: "Urlich", + age: 50, + parents: { + mother: "Helga", + father: "Brutus" }, - "cars" => array![ "Golf", "Mercedes", "Porsche" ] + cars: [ "Golf", "Mercedes", "Porsche" ] }; assert_eq!(object.pretty(2), @@ -374,7 +374,7 @@ fn null_len() { #[test] fn index_by_str() { let data = object!{ - "foo" => "bar" + foo: "bar" }; assert_eq!(data["foo"], "bar"); @@ -383,7 +383,7 @@ fn index_by_str() { #[test] fn index_by_string() { let data = object!{ - "foo" => "bar" + "foo": "bar" }; assert_eq!(data["foo".to_string()], "bar"); @@ -392,7 +392,7 @@ fn index_by_string() { #[test] fn index_by_string_ref() { let data = object!{ - "foo" => "bar" + foo: "bar" }; let key = "foo".to_string(); @@ -404,7 +404,7 @@ fn index_by_string_ref() { #[test] fn index_mut_by_str() { let mut data = object!{ - "foo" => Null + foo: null }; data["foo"] = "bar".into(); @@ -415,7 +415,7 @@ fn index_mut_by_str() { #[test] fn index_mut_by_string() { let mut data = object!{ - "foo" => Null + foo: null }; data["foo".to_string()] = "bar".into(); @@ -426,7 +426,7 @@ fn index_mut_by_string() { #[test] fn index_mut_by_string_ref() { let mut data = object!{ - "foo" => Null + foo: null }; let key = "foo".to_string(); @@ -440,7 +440,7 @@ fn index_mut_by_string_ref() { #[test] fn object_index_by_str() { let val = object!{ - "foo" => "bar" + foo: "bar" }; if let JsonValue::Object(data) = val { assert_eq!(data["foo"], "bar"); @@ -450,7 +450,7 @@ fn object_index_by_str() { #[test] fn object_index_by_string() { let val = object!{ - "foo" => "bar" + foo: "bar" }; if let JsonValue::Object(data) = val { @@ -461,7 +461,7 @@ fn object_index_by_string() { #[test] fn object_index_by_string_ref() { let val = object!{ - "foo" => "bar" + foo: "bar" }; let key = "foo".to_string(); @@ -475,7 +475,7 @@ fn object_index_by_string_ref() { #[test] fn object_index_mut_by_str() { let val = object!{ - "foo" => Null + foo: null }; if let JsonValue::Object(mut data) = val { @@ -488,7 +488,7 @@ fn object_index_mut_by_str() { #[test] fn object_index_mut_by_string() { let val = object!{ - "foo" => Null + foo: null }; if let JsonValue::Object(mut data) = val { @@ -501,7 +501,7 @@ fn object_index_mut_by_string() { #[test] fn object_index_mut_by_string_ref() { let val = object!{ - "foo" => Null + foo: null }; let key = "foo".to_string(); @@ -557,8 +557,8 @@ fn fmt_array() { #[test] fn fmt_object() { let data = object!{ - "foo" => "bar", - "answer" => 42 + foo: "bar", + answer: 42 }; assert_eq!(format!("{}", data), r#"{"foo":"bar","answer":42}"#); @@ -607,7 +607,7 @@ fn error_unexpected_token() { #[test] fn writer_generator() { let data = object!{ - "foo" => array!["bar", 100, true] + foo: ["bar", 100, true] }; let mut buf = Vec::new(); @@ -620,7 +620,7 @@ fn writer_generator() { #[test] fn pretty_writer_generator() { let data = object!{ - "foo" => array!["bar", 100, true] + foo: ["bar", 100, true] }; let mut buf = Vec::new(); @@ -633,31 +633,31 @@ fn pretty_writer_generator() { #[test] fn equality() { let left = object!{ - "foo" => array!["bar", 100, true] + foo: ["bar", 100, true] }; let left_copy = object!{ - "foo" => array!["bar", 100, true] + foo: ["bar", 100, true] }; let left_string = object!{ - "foo" => array![JsonValue::String("bar".to_string()), 100, true] + foo: [JsonValue::String("bar".to_string()), 100, true] }; let left_short = object!{ - "foo" => array![JsonValue::Short(unsafe { json::short::Short::from_slice("bar") }), 100, true] + foo: [JsonValue::Short(unsafe { json::short::Short::from_slice("bar") }), 100, true] }; let change_bool = object!{ - "foo" => array!["bar", 100, false] + foo: ["bar", 100, false] }; let change_string = object!{ - "foo" => array![JsonValue::String("sna".to_string()), 100, true] + foo: [JsonValue::String("sna".to_string()), 100, true] }; let change_short = object!{ - "foo" => array![JsonValue::Short(unsafe { json::short::Short::from_slice("sna") }), 100, true] + foo: [JsonValue::Short(unsafe { json::short::Short::from_slice("sna") }), 100, true] }; assert_eq!(left, left_copy);