Move json into it's own crate
Not everyone needs json, so no reason to force people to build it.
This commit is contained in:
parent
d4c20829f6
commit
8fa40fe7e1
@ -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;
|
||||
|
14
serde_json/Cargo.toml
Normal file
14
serde_json/Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "serde_json"
|
||||
version = "0.5.0"
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||
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" }
|
@ -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<Value>,
|
@ -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};
|
||||
|
@ -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)]
|
@ -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::{
|
@ -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<W, F=CompactFormatter> {
|
@ -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 {
|
@ -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" }
|
||||
|
@ -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");
|
||||
|
@ -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<String, i64> = json::from_str(&serialized_point).unwrap();
|
||||
let deserialized_map: BTreeMap<String, i64> =
|
||||
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:
|
||||
|
@ -2,6 +2,7 @@
|
||||
#![plugin(serde_macros)]
|
||||
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
extern crate test;
|
||||
|
||||
include!("../../serde_tests/tests/test.rs.in");
|
||||
|
@ -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]]
|
||||
|
@ -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"));
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/test.rs"));
|
||||
|
@ -1,4 +1,4 @@
|
||||
use serde::json;
|
||||
use serde_json;
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
struct Default {
|
||||
@ -33,30 +33,30 @@ enum SerEnum<A> {
|
||||
|
||||
#[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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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<T>(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<T>(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));
|
||||
|
@ -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() {
|
||||
|
@ -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<i32, i32, i32> = json::from_str("[1,2,3]").unwrap();
|
||||
let v: DeNamedTuple<i32, i32, i32> = 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<i32, i32, i32> = json::from_str(
|
||||
let v2: DeNamedMap<i32, i32, i32> = 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::<u32, u32, u32>).unwrap(),
|
||||
serde_json::to_string(&SerEnum::Unit::<u32, u32, u32>).unwrap(),
|
||||
"{\"Unit\":[]}"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
json::to_value(&SerEnum::Unit::<u32, u32, u32>),
|
||||
serde_json::to_value(&SerEnum::Unit::<u32, u32, u32>),
|
||||
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::<u32, u32, u32>
|
||||
);
|
||||
|
||||
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}}"
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user