Skip to content

Commit

Permalink
serialize: keep libserialize in sync with rustc-serialize to simplify…
Browse files Browse the repository at this point in the history
… merging
  • Loading branch information
erickt committed Dec 18, 2014
1 parent c0b2885 commit 11d9175
Showing 1 changed file with 3 additions and 28 deletions.
31 changes: 3 additions & 28 deletions src/libserialize/json.rs
Expand Up @@ -2016,7 +2016,6 @@ macro_rules! read_primitive {

impl ::Decoder<DecoderError> for Decoder {
fn read_nil(&mut self) -> DecodeResult<()> {
debug!("read_nil");
expect!(self.pop(), Null)
}

Expand All @@ -2034,7 +2033,6 @@ impl ::Decoder<DecoderError> for Decoder {
fn read_f32(&mut self) -> DecodeResult<f32> { self.read_f64().map(|x| x as f32) }

fn read_f64(&mut self) -> DecodeResult<f64> {
debug!("read_f64");
match self.pop() {
Json::I64(f) => Ok(f as f64),
Json::U64(f) => Ok(f as f64),
Expand All @@ -2053,7 +2051,6 @@ impl ::Decoder<DecoderError> for Decoder {
}

fn read_bool(&mut self) -> DecodeResult<bool> {
debug!("read_bool");
expect!(self.pop(), Boolean)
}

Expand All @@ -2071,22 +2068,19 @@ impl ::Decoder<DecoderError> for Decoder {
}

fn read_str(&mut self) -> DecodeResult<string::String> {
debug!("read_str");
expect!(self.pop(), String)
}

fn read_enum<T, F>(&mut self, name: &str, f: F) -> DecodeResult<T> where
F: FnOnce(&mut Decoder) -> DecodeResult<T>,
{
debug!("read_enum({})", name);
f(self)
}

fn read_enum_variant<T, F>(&mut self, names: &[&str],
mut f: F) -> DecodeResult<T>
where F: FnMut(&mut Decoder, uint) -> DecodeResult<T>,
{
debug!("read_enum_variant(names={})", names);
let name = match self.pop() {
Json::String(s) => s,
Json::Object(mut o) => {
Expand Down Expand Up @@ -2129,14 +2123,12 @@ impl ::Decoder<DecoderError> for Decoder {
fn read_enum_variant_arg<T, F>(&mut self, idx: uint, f: F) -> DecodeResult<T> where
F: FnOnce(&mut Decoder) -> DecodeResult<T>,
{
debug!("read_enum_variant_arg(idx={})", idx);
f(self)
}

fn read_enum_struct_variant<T, F>(&mut self, names: &[&str], f: F) -> DecodeResult<T> where
F: FnMut(&mut Decoder, uint) -> DecodeResult<T>,
{
debug!("read_enum_struct_variant(names={})", names);
self.read_enum_variant(names, f)
}

Expand All @@ -2148,14 +2140,12 @@ impl ::Decoder<DecoderError> for Decoder {
-> DecodeResult<T> where
F: FnOnce(&mut Decoder) -> DecodeResult<T>,
{
debug!("read_enum_struct_variant_field(name={}, idx={})", name, idx);
self.read_enum_variant_arg(idx, f)
}

fn read_struct<T, F>(&mut self, name: &str, len: uint, f: F) -> DecodeResult<T> where
F: FnOnce(&mut Decoder) -> DecodeResult<T>,
{
debug!("read_struct(name={}, len={})", name, len);
let value = try!(f(self));
self.pop();
Ok(value)
Expand All @@ -2168,7 +2158,6 @@ impl ::Decoder<DecoderError> for Decoder {
-> DecodeResult<T> where
F: FnOnce(&mut Decoder) -> DecodeResult<T>,
{
debug!("read_struct_field(name={}, idx={})", name, idx);
let mut obj = try!(expect!(self.pop(), Object));

let value = match obj.remove(&name.to_string()) {
Expand All @@ -2193,7 +2182,6 @@ impl ::Decoder<DecoderError> for Decoder {
fn read_tuple<T, F>(&mut self, tuple_len: uint, f: F) -> DecodeResult<T> where
F: FnOnce(&mut Decoder) -> DecodeResult<T>,
{
debug!("read_tuple()");
self.read_seq(move |d, len| {
if len == tuple_len {
f(d)
Expand All @@ -2206,7 +2194,6 @@ impl ::Decoder<DecoderError> for Decoder {
fn read_tuple_arg<T, F>(&mut self, idx: uint, f: F) -> DecodeResult<T> where
F: FnOnce(&mut Decoder) -> DecodeResult<T>,
{
debug!("read_tuple_arg(idx={})", idx);
self.read_seq_elt(idx, f)
}

Expand All @@ -2217,7 +2204,6 @@ impl ::Decoder<DecoderError> for Decoder {
-> DecodeResult<T> where
F: FnOnce(&mut Decoder) -> DecodeResult<T>,
{
debug!("read_tuple_struct(name={})", name);
self.read_tuple(len, f)
}

Expand All @@ -2227,14 +2213,12 @@ impl ::Decoder<DecoderError> for Decoder {
-> DecodeResult<T> where
F: FnOnce(&mut Decoder) -> DecodeResult<T>,
{
debug!("read_tuple_struct_arg(idx={})", idx);
self.read_tuple_arg(idx, f)
}

fn read_option<T, F>(&mut self, mut f: F) -> DecodeResult<T> where
F: FnMut(&mut Decoder, bool) -> DecodeResult<T>,
{
debug!("read_option()");
match self.pop() {
Json::Null => f(self, false),
value => { self.stack.push(value); f(self, true) }
Expand All @@ -2244,7 +2228,6 @@ impl ::Decoder<DecoderError> for Decoder {
fn read_seq<T, F>(&mut self, f: F) -> DecodeResult<T> where
F: FnOnce(&mut Decoder, uint) -> DecodeResult<T>,
{
debug!("read_seq()");
let array = try!(expect!(self.pop(), Array));
let len = array.len();
for v in array.into_iter().rev() {
Expand All @@ -2256,14 +2239,12 @@ impl ::Decoder<DecoderError> for Decoder {
fn read_seq_elt<T, F>(&mut self, idx: uint, f: F) -> DecodeResult<T> where
F: FnOnce(&mut Decoder) -> DecodeResult<T>,
{
debug!("read_seq_elt(idx={})", idx);
f(self)
}

fn read_map<T, F>(&mut self, f: F) -> DecodeResult<T> where
F: FnOnce(&mut Decoder, uint) -> DecodeResult<T>,
{
debug!("read_map()");
let obj = try!(expect!(self.pop(), Object));
let len = obj.len();
for (key, value) in obj.into_iter() {
Expand All @@ -2276,14 +2257,12 @@ impl ::Decoder<DecoderError> for Decoder {
fn read_map_elt_key<T, F>(&mut self, idx: uint, f: F) -> DecodeResult<T> where
F: FnOnce(&mut Decoder) -> DecodeResult<T>,
{
debug!("read_map_elt_key(idx={})", idx);
f(self)
}

fn read_map_elt_val<T, F>(&mut self, idx: uint, f: F) -> DecodeResult<T> where
F: FnOnce(&mut Decoder) -> DecodeResult<T>,
{
debug!("read_map_elt_val(idx={})", idx);
f(self)
}

Expand Down Expand Up @@ -2445,9 +2424,7 @@ mod tests {
use super::ParserError::*;
use super::DecoderError::*;
use super::JsonEvent::*;
use super::ParserState::*;
use super::StackElement::*;
use super::InternalStackElement::*;
use super::{PrettyEncoder, Json, from_str, DecodeResult, DecoderError, JsonEvent, Parser,
StackElement, Stack, Encoder, Decoder};
use std::{i64, u64, f32, f64, io};
Expand Down Expand Up @@ -2682,8 +2659,6 @@ mod tests {
}

fn with_str_writer<F>(f: F) -> string::String where F: FnOnce(&mut io::Writer){
use std::str;

let mut m = Vec::new();
f(&mut m as &mut io::Writer);
string::String::from_utf8(m).unwrap()
Expand Down Expand Up @@ -2760,9 +2735,9 @@ mod tests {
fn test_write_char() {
check_encoder_for_simple!('a', "\"a\"");
check_encoder_for_simple!('\t', "\"\\t\"");
check_encoder_for_simple!('\u00a0', "\"\u00a0\"");
check_encoder_for_simple!('\uabcd', "\"\uabcd\"");
check_encoder_for_simple!('\U0010ffff', "\"\U0010ffff\"");
check_encoder_for_simple!('\u{00a0}', "\"\u{00a0}\"");
check_encoder_for_simple!('\u{abcd}', "\"\u{abcd}\"");
check_encoder_for_simple!('\u{10ffff}', "\"\u{10ffff}\"");
}

#[test]
Expand Down

0 comments on commit 11d9175

Please sign in to comment.