From 8fa40fe7e1279d30b400fa97cdb4eca98267b5a0 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Wed, 22 Jul 2015 08:06:47 -0700 Subject: [PATCH] Move json into it's own crate Not everyone needs json, so no reason to force people to build it. --- serde/src/lib.rs | 1 - serde_json/Cargo.toml | 14 +++++ {serde/src/json => serde_json/src}/builder.rs | 5 +- {serde/src/json => serde_json/src}/de.rs | 4 +- {serde/src/json => serde_json/src}/error.rs | 2 +- .../src/json/mod.rs => serde_json/src/lib.rs | 3 + {serde/src/json => serde_json/src}/ser.rs | 2 +- {serde/src/json => serde_json/src}/value.rs | 7 ++- serde_macros/Cargo.toml | 1 + serde_macros/benches/bench.rs | 1 + serde_macros/examples/json.rs | 18 +++--- serde_macros/tests/test.rs | 1 + serde_tests/Cargo.toml | 1 + serde_tests/benches/bench.rs | 1 + serde_tests/benches/bench_log.rs | 34 +++++------ serde_tests/tests/test.rs | 1 + serde_tests/tests/test_annotations.rs | 18 +++--- serde_tests/tests/test_bytes.rs | 14 ++--- serde_tests/tests/test_json.rs | 16 ++--- serde_tests/tests/test_json_builder.rs | 4 +- serde_tests/tests/test_macros.rs | 58 +++++++++---------- 21 files changed, 116 insertions(+), 90 deletions(-) create mode 100644 serde_json/Cargo.toml rename {serde/src/json => serde_json/src}/builder.rs (97%) rename {serde/src/json => serde_json/src}/de.rs (99%) rename {serde/src/json => serde_json/src}/error.rs (99%) rename serde/src/json/mod.rs => serde_json/src/lib.rs (98%) rename {serde/src/json => serde_json/src}/ser.rs (99%) rename {serde/src/json => serde_json/src}/value.rs (99%) diff --git a/serde/src/lib.rs b/serde/src/lib.rs index 92d86c78..b573c5b9 100644 --- a/serde/src/lib.rs +++ b/serde/src/lib.rs @@ -22,5 +22,4 @@ pub use de::{Deserialize, Deserializer, Error}; pub mod bytes; pub mod de; pub mod iter; -pub mod json; pub mod ser; diff --git a/serde_json/Cargo.toml b/serde_json/Cargo.toml new file mode 100644 index 00000000..dbde52a9 --- /dev/null +++ b/serde_json/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "serde_json" +version = "0.5.0" +authors = ["Erick Tryzelaar "] +license = "MIT/Apache-2.0" +description = "A JSON serialization file format" +repository = "https://github.com/serde-rs/serde" +documentation = "http://serde-rs.github.io/serde/serde" +readme = "README.md" +keywords = ["serialization", "json"] + +[dependencies] +num = "*" +serde = { version = "*", path = "../serde" } diff --git a/serde/src/json/builder.rs b/serde_json/src/builder.rs similarity index 97% rename from serde/src/json/builder.rs rename to serde_json/src/builder.rs index 3db2c4ed..2743b3d9 100644 --- a/serde/src/json/builder.rs +++ b/serde_json/src/builder.rs @@ -10,8 +10,9 @@ use std::collections::BTreeMap; -use ser::{self, Serialize}; -use json::value::{self, Value}; +use serde::ser::{self, Serialize}; + +use value::{self, Value}; pub struct ArrayBuilder { array: Vec, diff --git a/serde/src/json/de.rs b/serde_json/src/de.rs similarity index 99% rename from serde/src/json/de.rs rename to serde_json/src/de.rs index a3140684..8bb33931 100644 --- a/serde/src/json/de.rs +++ b/serde_json/src/de.rs @@ -3,8 +3,8 @@ use std::i32; use std::io; use std::str; -use de; -use iter::LineColIterator; +use serde::de; +use serde::iter::LineColIterator; use super::error::{Error, ErrorCode}; diff --git a/serde/src/json/error.rs b/serde_json/src/error.rs similarity index 99% rename from serde/src/json/error.rs rename to serde_json/src/error.rs index 29570ebd..171e2459 100644 --- a/serde/src/json/error.rs +++ b/serde_json/src/error.rs @@ -2,7 +2,7 @@ use std::error; use std::fmt; use std::io; -use de; +use serde::de; /// The errors that can arise while parsing a JSON stream. #[derive(Clone, PartialEq)] diff --git a/serde/src/json/mod.rs b/serde_json/src/lib.rs similarity index 98% rename from serde/src/json/mod.rs rename to serde_json/src/lib.rs index 3a3a3526..56468518 100644 --- a/serde/src/json/mod.rs +++ b/serde_json/src/lib.rs @@ -92,6 +92,9 @@ //! } //! ``` +extern crate num; +extern crate serde; + pub use self::de::{Deserializer, from_str}; pub use self::error::{Error, ErrorCode}; pub use self::ser::{ diff --git a/serde/src/json/ser.rs b/serde_json/src/ser.rs similarity index 99% rename from serde/src/json/ser.rs rename to serde_json/src/ser.rs index 71279920..d432c49d 100644 --- a/serde/src/json/ser.rs +++ b/serde_json/src/ser.rs @@ -2,7 +2,7 @@ use std::io; use std::num::FpCategory; use std::string::FromUtf8Error; -use ser; +use serde::ser; /// A structure for implementing serialization to JSON. pub struct Serializer { diff --git a/serde/src/json/value.rs b/serde_json/src/value.rs similarity index 99% rename from serde/src/json/value.rs rename to serde_json/src/value.rs index ec60f459..45cb7785 100644 --- a/serde/src/json/value.rs +++ b/serde_json/src/value.rs @@ -6,9 +6,10 @@ use std::vec; use num::NumCast; -use de; -use ser; -use super::error::Error; +use serde::de; +use serde::ser; + +use error::Error; #[derive(Clone, PartialEq)] pub enum Value { diff --git a/serde_macros/Cargo.toml b/serde_macros/Cargo.toml index e43f3cbe..fc2d9e40 100644 --- a/serde_macros/Cargo.toml +++ b/serde_macros/Cargo.toml @@ -17,3 +17,4 @@ serde_codegen = { version = "*", path = "../serde_codegen", default-features = f num = "*" rustc-serialize = "*" serde = { version = "*", path = "../serde", features = ["nightly"] } +serde_json = { version = "*", path = "../serde_json" } diff --git a/serde_macros/benches/bench.rs b/serde_macros/benches/bench.rs index 519c189f..514edc48 100644 --- a/serde_macros/benches/bench.rs +++ b/serde_macros/benches/bench.rs @@ -4,6 +4,7 @@ extern crate num; extern crate rustc_serialize; extern crate serde; +extern crate serde_json; extern crate test; include!("../../serde_tests/benches/bench.rs.in"); diff --git a/serde_macros/examples/json.rs b/serde_macros/examples/json.rs index 3da197df..50f5d199 100644 --- a/serde_macros/examples/json.rs +++ b/serde_macros/examples/json.rs @@ -2,9 +2,9 @@ #![plugin(serde_macros)] extern crate serde; +extern crate serde_json; use std::collections::BTreeMap; -use serde::json; // Creating serializable types with serde is quite simple with `serde_macros`. It implements a // syntax extension that automatically generates the necessary serde trait implementations. @@ -18,7 +18,7 @@ fn main() { let point = Point { x: 5, y: 6 }; // Serializing to JSON is pretty simple by using the `to_string` method: - let serialized_point = json::to_string(&point).unwrap(); + let serialized_point = serde_json::to_string(&point).unwrap(); println!("{}", serialized_point); // prints: @@ -26,7 +26,7 @@ fn main() { // {"x":5,"y":6} // There is also support for pretty printing using `to_string_pretty`: - let serialized_point = json::to_string_pretty(&point).unwrap(); + let serialized_point = serde_json::to_string_pretty(&point).unwrap(); println!("{}", serialized_point); // prints: @@ -37,7 +37,7 @@ fn main() { // } // Values can also be deserialized with the same style using `from_str`: - let deserialized_point: Point = json::from_str(&serialized_point).unwrap(); + let deserialized_point: Point = serde_json::from_str(&serialized_point).unwrap(); println!("{:?}", deserialized_point); // prints: @@ -46,16 +46,18 @@ fn main() { // `Point`s aren't the only type that can be serialized to. Because `Point` members have the // same type, they can be also serialized into a map. Also, - let deserialized_map: BTreeMap = json::from_str(&serialized_point).unwrap(); + let deserialized_map: BTreeMap = + serde_json::from_str(&serialized_point).unwrap(); println!("{:?}", deserialized_map); // prints: // // {"x": 5, "y": 6} - // If you need to accept arbitrary data, you can also deserialize into `json::Value`, which - // can represent all JSON values. - let deserialized_value: json::Value = json::from_str(&serialized_point).unwrap(); + // If you need to accept arbitrary data, you can also deserialize into `serde_json::Value`, + // which can represent all JSON values. + let deserialized_value: serde_json::Value = + serde_json::from_str(&serialized_point).unwrap(); println!("{:?}", deserialized_value); // prints: diff --git a/serde_macros/tests/test.rs b/serde_macros/tests/test.rs index fd353e1b..7e98981c 100644 --- a/serde_macros/tests/test.rs +++ b/serde_macros/tests/test.rs @@ -2,6 +2,7 @@ #![plugin(serde_macros)] extern crate serde; +extern crate serde_json; extern crate test; include!("../../serde_tests/tests/test.rs.in"); diff --git a/serde_tests/Cargo.toml b/serde_tests/Cargo.toml index 68356a29..2fdf5510 100644 --- a/serde_tests/Cargo.toml +++ b/serde_tests/Cargo.toml @@ -19,6 +19,7 @@ serde_codegen = { version = "*", path = "../serde_codegen", features = ["with-sy num = "*" rustc-serialize = "*" serde = { version = "*", path = "../serde" } +serde_json = { version = "*", path = "../serde_json" } syntex = "*" [[test]] diff --git a/serde_tests/benches/bench.rs b/serde_tests/benches/bench.rs index 181c4c61..7cc2fc32 100644 --- a/serde_tests/benches/bench.rs +++ b/serde_tests/benches/bench.rs @@ -3,6 +3,7 @@ extern crate num; extern crate rustc_serialize; extern crate serde; +extern crate serde_json; extern crate test; include!(concat!(env!("OUT_DIR"), "/bench.rs")); diff --git a/serde_tests/benches/bench_log.rs b/serde_tests/benches/bench_log.rs index 925b03ed..4fa108da 100644 --- a/serde_tests/benches/bench_log.rs +++ b/serde_tests/benches/bench_log.rs @@ -5,9 +5,9 @@ use test::Bencher; use rustc_serialize; use serde::de::{self, Deserialize, Deserializer}; -use serde::json::ser::escape_str; -use serde::json; use serde::ser::{self, Serialize, Serializer}; +use serde_json::ser::escape_str; +use serde_json; use std::str::FromStr; use rustc_serialize::Encodable; @@ -1123,18 +1123,18 @@ fn bench_encoder(b: &mut Bencher) { #[test] fn test_serializer() { let log = Log::new(); - let json = json::to_vec(&log); + let json = serde_json::to_vec(&log); assert_eq!(json, JSON_STR.as_bytes()); } #[bench] fn bench_serializer(b: &mut Bencher) { let log = Log::new(); - let json = json::to_vec(&log); + let json = serde_json::to_vec(&log); b.bytes = json.len() as u64; b.iter(|| { - let _ = json::to_vec(&log); + let _ = serde_json::to_vec(&log); }); } @@ -1142,7 +1142,7 @@ fn bench_serializer(b: &mut Bencher) { fn test_serializer_vec() { let log = Log::new(); let wr = Vec::with_capacity(1024); - let mut serializer = json::Serializer::new(wr); + let mut serializer = serde_json::Serializer::new(wr); log.serialize(&mut serializer).unwrap(); let json = serializer.into_inner(); @@ -1152,7 +1152,7 @@ fn test_serializer_vec() { #[bench] fn bench_serializer_vec(b: &mut Bencher) { let log = Log::new(); - let json = json::to_vec(&log); + let json = serde_json::to_vec(&log); b.bytes = json.len() as u64; let mut wr = Vec::with_capacity(1024); @@ -1160,7 +1160,7 @@ fn bench_serializer_vec(b: &mut Bencher) { b.iter(|| { wr.clear(); - let mut serializer = json::Serializer::new(wr.by_ref()); + let mut serializer = serde_json::Serializer::new(wr.by_ref()); log.serialize(&mut serializer).unwrap(); let _json = serializer.into_inner(); }); @@ -1169,7 +1169,7 @@ fn bench_serializer_vec(b: &mut Bencher) { #[bench] fn bench_serializer_slice(b: &mut Bencher) { let log = Log::new(); - let json = json::to_vec(&log); + let json = serde_json::to_vec(&log); b.bytes = json.len() as u64; let mut buf = [0; 1024]; @@ -1178,7 +1178,7 @@ fn bench_serializer_slice(b: &mut Bencher) { for item in buf.iter_mut(){ *item = 0; } let mut wr = &mut buf[..]; - let mut serializer = json::Serializer::new(wr.by_ref()); + let mut serializer = serde_json::Serializer::new(wr.by_ref()); log.serialize(&mut serializer).unwrap(); let _json = serializer.into_inner(); }); @@ -1191,7 +1191,7 @@ fn test_serializer_my_mem_writer0() { let mut wr = MyMemWriter0::with_capacity(1024); { - let mut serializer = json::Serializer::new(wr.by_ref()); + let mut serializer = serde_json::Serializer::new(wr.by_ref()); log.serialize(&mut serializer).unwrap(); let _json = serializer.into_inner(); } @@ -1202,7 +1202,7 @@ fn test_serializer_my_mem_writer0() { #[bench] fn bench_serializer_my_mem_writer0(b: &mut Bencher) { let log = Log::new(); - let json = json::to_vec(&log); + let json = serde_json::to_vec(&log); b.bytes = json.len() as u64; let mut wr = MyMemWriter0::with_capacity(1024); @@ -1210,7 +1210,7 @@ fn bench_serializer_my_mem_writer0(b: &mut Bencher) { b.iter(|| { wr.buf.clear(); - let mut serializer = json::Serializer::new(wr.by_ref()); + let mut serializer = serde_json::Serializer::new(wr.by_ref()); log.serialize(&mut serializer).unwrap(); let _json = serializer.into_inner(); }); @@ -1223,7 +1223,7 @@ fn test_serializer_my_mem_writer1() { let mut wr = MyMemWriter1::with_capacity(1024); { - let mut serializer = json::Serializer::new(wr.by_ref()); + let mut serializer = serde_json::Serializer::new(wr.by_ref()); log.serialize(&mut serializer).unwrap(); let _json = serializer.into_inner(); } @@ -1234,7 +1234,7 @@ fn test_serializer_my_mem_writer1() { #[bench] fn bench_serializer_my_mem_writer1(b: &mut Bencher) { let log = Log::new(); - let json = json::to_vec(&log); + let json = serde_json::to_vec(&log); b.bytes = json.len() as u64; let mut wr = MyMemWriter1::with_capacity(1024); @@ -1242,7 +1242,7 @@ fn bench_serializer_my_mem_writer1(b: &mut Bencher) { b.iter(|| { wr.buf.clear(); - let mut serializer = json::Serializer::new(wr.by_ref()); + let mut serializer = serde_json::Serializer::new(wr.by_ref()); log.serialize(&mut serializer).unwrap(); let _json = serializer.into_inner(); }); @@ -1593,6 +1593,6 @@ fn bench_deserializer(b: &mut Bencher) { b.bytes = JSON_STR.len() as u64; b.iter(|| { - let _log: Log = json::from_str(JSON_STR).unwrap(); + let _log: Log = serde_json::from_str(JSON_STR).unwrap(); }); } diff --git a/serde_tests/tests/test.rs b/serde_tests/tests/test.rs index 732c1432..933c6b85 100644 --- a/serde_tests/tests/test.rs +++ b/serde_tests/tests/test.rs @@ -1,3 +1,4 @@ extern crate serde; +extern crate serde_json; include!(concat!(env!("OUT_DIR"), "/test.rs")); diff --git a/serde_tests/tests/test_annotations.rs b/serde_tests/tests/test_annotations.rs index 37746ae5..9a21e0bf 100644 --- a/serde_tests/tests/test_annotations.rs +++ b/serde_tests/tests/test_annotations.rs @@ -1,4 +1,4 @@ -use serde::json; +use serde_json; #[derive(Debug, PartialEq, Serialize, Deserialize)] struct Default { @@ -33,30 +33,30 @@ enum SerEnum { #[test] fn test_default() { - let deserialized_value: Default = json::from_str(&"{\"a1\":1,\"a2\":2}").unwrap(); + let deserialized_value: Default = serde_json::from_str(&"{\"a1\":1,\"a2\":2}").unwrap(); assert_eq!(deserialized_value, Default { a1: 1, a2: 2 }); - let deserialized_value: Default = json::from_str(&"{\"a1\":1}").unwrap(); + let deserialized_value: Default = serde_json::from_str(&"{\"a1\":1}").unwrap(); assert_eq!(deserialized_value, Default { a1: 1, a2: 0 }); } #[test] fn test_rename() { let value = Rename { a1: 1, a2: 2 }; - let serialized_value = json::to_string(&value).unwrap(); + let serialized_value = serde_json::to_string(&value).unwrap(); assert_eq!(serialized_value, "{\"a1\":1,\"a3\":2}"); - let deserialized_value: Rename = json::from_str(&serialized_value).unwrap(); + let deserialized_value: Rename = serde_json::from_str(&serialized_value).unwrap(); assert_eq!(value, deserialized_value); } #[test] fn test_format_rename() { let value = FormatRename { a1: 1, a2: 2 }; - let serialized_value = json::to_string(&value).unwrap(); + let serialized_value = serde_json::to_string(&value).unwrap(); assert_eq!(serialized_value, "{\"a1\":1,\"a5\":2}"); - let deserialized_value = json::from_str("{\"a1\":1,\"a5\":2}").unwrap(); + let deserialized_value = serde_json::from_str("{\"a1\":1,\"a5\":2}").unwrap(); assert_eq!(value, deserialized_value); } @@ -64,10 +64,10 @@ fn test_format_rename() { fn test_enum_format_rename() { let s1 = String::new(); let value = SerEnum::Map { a: 0i8, b: s1 }; - let serialized_value = json::to_string(&value).unwrap(); + let serialized_value = serde_json::to_string(&value).unwrap(); let ans = "{\"Map\":{\"a\":0,\"d\":\"\"}}"; assert_eq!(serialized_value, ans); - let deserialized_value = json::from_str(ans).unwrap(); + let deserialized_value = serde_json::from_str(ans).unwrap(); assert_eq!(value, deserialized_value); } diff --git a/serde_tests/tests/test_bytes.rs b/serde_tests/tests/test_bytes.rs index a72cf1ae..3ca97285 100644 --- a/serde_tests/tests/test_bytes.rs +++ b/serde_tests/tests/test_bytes.rs @@ -1,7 +1,7 @@ use serde; use serde::Serialize; use serde::bytes::{ByteBuf, Bytes}; -use serde::json; +use serde_json; /////////////////////////////////////////////////////////////////////////////// @@ -144,11 +144,11 @@ impl serde::Deserializer for BytesDeserializer { fn test_bytes_ser_json() { let buf = vec![]; let bytes = Bytes::from(&buf); - assert_eq!(json::to_string(&bytes).unwrap(), "[]".to_string()); + assert_eq!(serde_json::to_string(&bytes).unwrap(), "[]".to_string()); let buf = vec![1, 2, 3]; let bytes = Bytes::from(&buf); - assert_eq!(json::to_string(&bytes).unwrap(), "[1,2,3]".to_string()); + assert_eq!(serde_json::to_string(&bytes).unwrap(), "[1,2,3]".to_string()); } #[test] @@ -167,10 +167,10 @@ fn test_bytes_ser_bytes() { #[test] fn test_byte_buf_ser_json() { let bytes = ByteBuf::new(); - assert_eq!(json::to_string(&bytes).unwrap(), "[]".to_string()); + assert_eq!(serde_json::to_string(&bytes).unwrap(), "[]".to_string()); let bytes = ByteBuf::from(vec![1, 2, 3]); - assert_eq!(json::to_string(&bytes).unwrap(), "[1,2,3]".to_string()); + assert_eq!(serde_json::to_string(&bytes).unwrap(), "[1,2,3]".to_string()); } #[test] @@ -189,11 +189,11 @@ fn test_byte_buf_ser_bytes() { #[test] fn test_byte_buf_de_json() { let bytes = ByteBuf::new(); - let v: ByteBuf = json::from_str("[]").unwrap(); + let v: ByteBuf = serde_json::from_str("[]").unwrap(); assert_eq!(v, bytes); let bytes = ByteBuf::from(vec![1, 2, 3]); - let v: ByteBuf = json::from_str("[1, 2, 3]").unwrap(); + let v: ByteBuf = serde_json::from_str("[1, 2, 3]").unwrap(); assert_eq!(v, bytes); } diff --git a/serde_tests/tests/test_json.rs b/serde_tests/tests/test_json.rs index f2dd9a29..0c4ccd65 100644 --- a/serde_tests/tests/test_json.rs +++ b/serde_tests/tests/test_json.rs @@ -4,7 +4,7 @@ use std::collections::BTreeMap; use serde::de; use serde::ser; -use serde::json::{ +use serde_json::{ self, Value, from_str, @@ -12,7 +12,7 @@ use serde::json::{ to_value, }; -use serde::json::error::{Error, ErrorCode}; +use serde_json::error::{Error, ErrorCode}; macro_rules! treemap { ($($k:expr => $v:expr),*) => ({ @@ -48,11 +48,11 @@ fn test_encode_ok(errors: &[(T, &str)]) for &(ref value, out) in errors { let out = out.to_string(); - let s = json::to_string(value).unwrap(); + let s = serde_json::to_string(value).unwrap(); assert_eq!(s, out); let v = to_value(&value); - let s = json::to_string(&v).unwrap(); + let s = serde_json::to_string(&v).unwrap(); assert_eq!(s, out); } } @@ -63,11 +63,11 @@ fn test_pretty_encode_ok(errors: &[(T, &str)]) for &(ref value, out) in errors { let out = out.to_string(); - let s = json::to_string_pretty(value).unwrap(); + let s = serde_json::to_string_pretty(value).unwrap(); assert_eq!(s, out); let v = to_value(&value); - let s = json::to_string_pretty(&v).unwrap(); + let s = serde_json::to_string_pretty(&v).unwrap(); assert_eq!(s, out); } } @@ -1080,7 +1080,7 @@ fn test_missing_fmt_renamed_field() { #[test] fn test_find_path() { - let obj: Value = json::from_str(r#"{"x": {"a": 1}, "y": 2}"#).unwrap(); + let obj: Value = serde_json::from_str(r#"{"x": {"a": 1}, "y": 2}"#).unwrap(); assert!(obj.find_path(&["x", "a"]).unwrap() == &Value::U64(1)); assert!(obj.find_path(&["y"]).unwrap() == &Value::U64(2)); @@ -1089,7 +1089,7 @@ fn test_find_path() { #[test] fn test_lookup() { - let obj: Value = json::from_str(r#"{"x": {"a": 1}, "y": 2}"#).unwrap(); + let obj: Value = serde_json::from_str(r#"{"x": {"a": 1}, "y": 2}"#).unwrap(); assert!(obj.lookup("x.a").unwrap() == &Value::U64(1)); assert!(obj.lookup("y").unwrap() == &Value::U64(2)); diff --git a/serde_tests/tests/test_json_builder.rs b/serde_tests/tests/test_json_builder.rs index f17dd70a..55fcff08 100644 --- a/serde_tests/tests/test_json_builder.rs +++ b/serde_tests/tests/test_json_builder.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; -use serde::json::value::Value; -use serde::json::builder::{ArrayBuilder, ObjectBuilder}; +use serde_json::value::Value; +use serde_json::builder::{ArrayBuilder, ObjectBuilder}; #[test] fn test_array_builder() { diff --git a/serde_tests/tests/test_macros.rs b/serde_tests/tests/test_macros.rs index 524147bf..d7af9855 100644 --- a/serde_tests/tests/test_macros.rs +++ b/serde_tests/tests/test_macros.rs @@ -1,5 +1,5 @@ use std::collections::BTreeMap; -use serde::json::{self, Value}; +use serde_json::{self, Value}; macro_rules! btreemap { () => { @@ -136,19 +136,19 @@ fn test_named_unit() { let named_unit = NamedUnit; assert_eq!( - json::to_string(&named_unit).unwrap(), + serde_json::to_string(&named_unit).unwrap(), "null".to_string() ); assert_eq!( - json::to_value(&named_unit), + serde_json::to_value(&named_unit), Value::Null ); - let v: NamedUnit = json::from_str("null").unwrap(); + let v: NamedUnit = serde_json::from_str("null").unwrap(); assert_eq!(v, named_unit); - let v: NamedUnit = json::from_value(Value::Null).unwrap(); + let v: NamedUnit = serde_json::from_value(Value::Null).unwrap(); assert_eq!(v, named_unit); } @@ -160,25 +160,25 @@ fn test_ser_named_tuple() { let named_tuple = SerNamedTuple(&a, &mut b, c); assert_eq!( - json::to_string(&named_tuple).unwrap(), + serde_json::to_string(&named_tuple).unwrap(), "[5,6,7]" ); assert_eq!( - json::to_value(&named_tuple), + serde_json::to_value(&named_tuple), Value::Array(vec![Value::U64(5), Value::U64(6), Value::U64(7)]) ); } #[test] fn test_de_named_tuple() { - let v: DeNamedTuple = json::from_str("[1,2,3]").unwrap(); + let v: DeNamedTuple = serde_json::from_str("[1,2,3]").unwrap(); assert_eq!( v, DeNamedTuple(1, 2, 3) ); - let v: Value = json::from_str("[1,2,3]").unwrap(); + let v: Value = serde_json::from_str("[1,2,3]").unwrap(); assert_eq!( v, Value::Array(vec![ @@ -201,12 +201,12 @@ fn test_ser_named_map() { }; assert_eq!( - json::to_string(&named_map).unwrap(), + serde_json::to_string(&named_map).unwrap(), "{\"a\":5,\"b\":6,\"c\":7}" ); assert_eq!( - json::to_value(&named_map), + serde_json::to_value(&named_map), Value::Object(btreemap![ "a".to_string() => Value::U64(5), "b".to_string() => Value::U64(6), @@ -223,12 +223,12 @@ fn test_de_named_map() { c: 7, }; - let v2: DeNamedMap = json::from_str( + let v2: DeNamedMap = serde_json::from_str( "{\"a\":5,\"b\":6,\"c\":7}" ).unwrap(); assert_eq!(v, v2); - let v2 = json::from_value(Value::Object(btreemap![ + let v2 = serde_json::from_value(Value::Object(btreemap![ "a".to_string() => Value::U64(5), "b".to_string() => Value::U64(6), "c".to_string() => Value::U64(7) @@ -239,12 +239,12 @@ fn test_de_named_map() { #[test] fn test_ser_enum_unit() { assert_eq!( - json::to_string(&SerEnum::Unit::).unwrap(), + serde_json::to_string(&SerEnum::Unit::).unwrap(), "{\"Unit\":[]}" ); assert_eq!( - json::to_value(&SerEnum::Unit::), + serde_json::to_value(&SerEnum::Unit::), Value::Object(btreemap!( "Unit".to_string() => Value::Array(vec![])) ) @@ -261,7 +261,7 @@ fn test_ser_enum_seq() { //let f = 6; assert_eq!( - json::to_string(&SerEnum::Seq( + serde_json::to_string(&SerEnum::Seq( a, b, &c, @@ -273,7 +273,7 @@ fn test_ser_enum_seq() { ); assert_eq!( - json::to_value(&SerEnum::Seq( + serde_json::to_value(&SerEnum::Seq( a, b, &c, @@ -304,7 +304,7 @@ fn test_ser_enum_map() { //let f = 6; assert_eq!( - json::to_string(&SerEnum::Map { + serde_json::to_string(&SerEnum::Map { a: a, b: b, c: &c, @@ -316,7 +316,7 @@ fn test_ser_enum_map() { ); assert_eq!( - json::to_value(&SerEnum::Map { + serde_json::to_value(&SerEnum::Map { a: a, b: b, c: &c, @@ -339,13 +339,13 @@ fn test_ser_enum_map() { #[test] fn test_de_enum_unit() { - let v: DeEnum<_, _, _> = json::from_str("{\"Unit\":[]}").unwrap(); + let v: DeEnum<_, _, _> = serde_json::from_str("{\"Unit\":[]}").unwrap(); assert_eq!( v, DeEnum::Unit:: ); - let v: DeEnum<_, _, _> = json::from_value(Value::Object(btreemap!( + let v: DeEnum<_, _, _> = serde_json::from_value(Value::Object(btreemap!( "Unit".to_string() => Value::Array(vec![])) )).unwrap(); assert_eq!( @@ -363,7 +363,7 @@ fn test_de_enum_seq() { let e = 5; //let f = 6; - let v: DeEnum<_, _, _> = json::from_str("{\"Seq\":[1,2,3,5]}").unwrap(); + let v: DeEnum<_, _, _> = serde_json::from_str("{\"Seq\":[1,2,3,5]}").unwrap(); assert_eq!( v, DeEnum::Seq( @@ -376,7 +376,7 @@ fn test_de_enum_seq() { ) ); - let v: DeEnum<_, _, _> = json::from_value(Value::Object(btreemap!( + let v: DeEnum<_, _, _> = serde_json::from_value(Value::Object(btreemap!( "Seq".to_string() => Value::Array(vec![ Value::U64(1), Value::U64(2), @@ -408,7 +408,7 @@ fn test_de_enum_map() { let e = 5; //let f = 6; - let v: DeEnum<_, _, _> = json::from_str( + let v: DeEnum<_, _, _> = serde_json::from_str( "{\"Map\":{\"a\":1,\"b\":2,\"c\":3,\"e\":5}}" ).unwrap(); assert_eq!( @@ -423,7 +423,7 @@ fn test_de_enum_map() { } ); - let v: DeEnum<_, _, _> = json::from_value(Value::Object(btreemap!( + let v: DeEnum<_, _, _> = serde_json::from_value(Value::Object(btreemap!( "Map".to_string() => Value::Object(btreemap![ "a".to_string() => Value::U64(1), "b".to_string() => Value::U64(2), @@ -452,26 +452,26 @@ fn test_lifetimes() { let value = 5; let lifetime = Lifetimes::LifetimeSeq(&value); assert_eq!( - json::to_string(&lifetime).unwrap(), + serde_json::to_string(&lifetime).unwrap(), "{\"LifetimeSeq\":[5]}" ); let lifetime = Lifetimes::NoLifetimeSeq(5); assert_eq!( - json::to_string(&lifetime).unwrap(), + serde_json::to_string(&lifetime).unwrap(), "{\"NoLifetimeSeq\":[5]}" ); let value = 5; let lifetime = Lifetimes::LifetimeMap { a: &value }; assert_eq!( - json::to_string(&lifetime).unwrap(), + serde_json::to_string(&lifetime).unwrap(), "{\"LifetimeMap\":{\"a\":5}}" ); let lifetime = Lifetimes::NoLifetimeMap { a: 5 }; assert_eq!( - json::to_string(&lifetime).unwrap(), + serde_json::to_string(&lifetime).unwrap(), "{\"NoLifetimeMap\":{\"a\":5}}" ); }