mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-27 16:57:56 +00:00
update to the latest nightly
This commit is contained in:
+2
-4
@@ -425,7 +425,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn test_encode_ok<
|
||||
T: PartialEq + Show + ToJson + ser::Serialize<super::Serializer<io::MemWriter>, io::IoError>
|
||||
T: PartialEq + Show + ToJson + ser::Serialize<super::Serializer<Vec<u8>>, io::IoError>
|
||||
>(errors: &[(T, &str)]) {
|
||||
for &(ref value, out) in errors.iter() {
|
||||
let out = out.to_string();
|
||||
@@ -439,7 +439,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn test_pretty_encode_ok<
|
||||
T: PartialEq + Show + ToJson + ser::Serialize<super::PrettySerializer<io::MemWriter>, io::IoError>
|
||||
T: PartialEq + Show + ToJson + ser::Serialize<super::PrettySerializer<Vec<u8>>, io::IoError>
|
||||
>(errors: &[(T, &str)]) {
|
||||
for &(ref value, out) in errors.iter() {
|
||||
let out = out.to_string();
|
||||
@@ -1370,7 +1370,6 @@ mod tests {
|
||||
#[test]
|
||||
fn test_encode_hashmap_with_numeric_key() {
|
||||
use std::str::from_utf8;
|
||||
use std::io::MemWriter;
|
||||
use std::collections::HashMap;
|
||||
let mut hm: HashMap<uint, bool> = HashMap::new();
|
||||
hm.insert(1, true);
|
||||
@@ -1386,7 +1385,6 @@ mod tests {
|
||||
#[test]
|
||||
fn test_prettyencode_hashmap_with_numeric_key() {
|
||||
use std::str::from_utf8;
|
||||
use std::io::MemWriter;
|
||||
use std::collections::HashMap;
|
||||
let mut hm: HashMap<uint, bool> = HashMap::new();
|
||||
hm.insert(1, true);
|
||||
|
||||
+9
-9
@@ -1,7 +1,7 @@
|
||||
use std::f32;
|
||||
use std::f64;
|
||||
use std::num::{Float, FPNaN, FPInfinite};
|
||||
use std::io::{IoError, IoResult, MemWriter};
|
||||
use std::io::{IoError, IoResult};
|
||||
|
||||
use ser::Serialize;
|
||||
use ser;
|
||||
@@ -587,18 +587,18 @@ pub fn to_writer<
|
||||
/// Encode the specified struct into a json `[u8]` buffer.
|
||||
#[inline]
|
||||
pub fn to_vec<
|
||||
T: Serialize<Serializer<MemWriter>, IoError>
|
||||
T: Serialize<Serializer<Vec<u8>>, IoError>
|
||||
>(value: &T) -> Vec<u8> {
|
||||
// We are writing to a Vec, which doesn't fail. So we can ignore
|
||||
// the error.
|
||||
let writer = MemWriter::with_capacity(128);
|
||||
to_writer(writer, value).unwrap().unwrap()
|
||||
let writer = Vec::with_capacity(128);
|
||||
to_writer(writer, value).unwrap()
|
||||
}
|
||||
|
||||
/// Encode the specified struct into a json `String` buffer.
|
||||
#[inline]
|
||||
pub fn to_string<
|
||||
T: Serialize<Serializer<MemWriter>, IoError>
|
||||
T: Serialize<Serializer<Vec<u8>>, IoError>
|
||||
>(value: &T) -> Result<String, Vec<u8>> {
|
||||
let buf = to_vec(value);
|
||||
String::from_utf8(buf)
|
||||
@@ -617,17 +617,17 @@ pub fn to_pretty_writer<
|
||||
|
||||
/// Encode the specified struct into a json `[u8]` buffer.
|
||||
pub fn to_pretty_vec<
|
||||
T: Serialize<PrettySerializer<MemWriter>, IoError>
|
||||
T: Serialize<PrettySerializer<Vec<u8>>, IoError>
|
||||
>(value: &T) -> Vec<u8> {
|
||||
// We are writing to a Vec, which doesn't fail. So we can ignore
|
||||
// the error.
|
||||
let writer = MemWriter::with_capacity(128);
|
||||
to_pretty_writer(writer, value).unwrap().unwrap()
|
||||
let writer = Vec::with_capacity(128);
|
||||
to_pretty_writer(writer, value).unwrap()
|
||||
}
|
||||
|
||||
/// Encode the specified struct into a json `String` buffer.
|
||||
pub fn to_pretty_string<
|
||||
T: Serialize<PrettySerializer<MemWriter>, IoError>
|
||||
T: Serialize<PrettySerializer<Vec<u8>>, IoError>
|
||||
>(value: &T) -> Result<String, Vec<u8>> {
|
||||
let buf = to_pretty_vec(value);
|
||||
String::from_utf8(buf)
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
use std::collections::{HashMap, TreeMap, tree_map};
|
||||
use std::fmt;
|
||||
use std::io::{ByRefWriter, IoResult, MemWriter};
|
||||
use std::io::{ByRefWriter, IoResult};
|
||||
use std::io;
|
||||
use std::str;
|
||||
use std::string;
|
||||
@@ -41,9 +41,9 @@ impl Value {
|
||||
|
||||
/// Serializes a json value into a string
|
||||
pub fn to_pretty_string(&self) -> string::String {
|
||||
let mut wr = MemWriter::new();
|
||||
let mut wr = Vec::new();
|
||||
self.to_pretty_writer(wr.by_ref()).unwrap();
|
||||
str::from_utf8(wr.unwrap().as_slice()).unwrap().to_string()
|
||||
str::from_utf8(wr.as_slice()).unwrap().to_string()
|
||||
}
|
||||
|
||||
/// If the Json value is an Object, returns the value associated with the provided key.
|
||||
|
||||
Reference in New Issue
Block a user