Uncomment more code

This commit is contained in:
Erick Tryzelaar
2014-05-30 22:43:01 -07:00
parent c6e503f8b3
commit 8526b9c480
+34 -30
View File
@@ -234,7 +234,9 @@ fn main() {
*/ */
use std::char; use std::char;
use std::f64;
use std::fmt; use std::fmt;
use std::io::MemWriter;
use std::io; use std::io;
use std::num; use std::num;
use std::str::ScalarValue; use std::str::ScalarValue;
@@ -246,6 +248,8 @@ use std::vec;
use de; use de;
use collections::{Deque, HashMap, RingBuf, TreeMap}; use collections::{Deque, HashMap, RingBuf, TreeMap};
use collections::treemap; use collections::treemap;
use serialize;
use serialize::{Encoder, Encodable};
/// Represents a json value /// Represents a json value
#[deriving(Clone, Eq, Show)] #[deriving(Clone, Eq, Show)]
@@ -412,7 +416,10 @@ impl de::Deserializer<ParserError> for JsonDeserializer {
// Special case treating enums as a String or a `{"variant": "...", "fields": [...]}`. // Special case treating enums as a String or a `{"variant": "...", "fields": [...]}`.
#[inline] #[inline]
fn expect_enum_start(&mut self, token: de::Token, _name: &str, variants: &[&str]) -> Result<uint, ParserError> { fn expect_enum_start(&mut self,
token: de::Token,
_name: &str,
variants: &[&str]) -> Result<uint, ParserError> {
let variant = match token { let variant = match token {
de::String(variant) => { de::String(variant) => {
self.stack.push(JsonDeserializerEndState); self.stack.push(JsonDeserializerEndState);
@@ -592,7 +599,6 @@ fn spaces(n: uint) -> String {
return ss return ss
} }
/*
/// A structure for implementing serialization to JSON. /// A structure for implementing serialization to JSON.
pub struct Encoder<'a> { pub struct Encoder<'a> {
wr: &'a mut io::Writer, wr: &'a mut io::Writer,
@@ -606,7 +612,10 @@ impl<'a> Encoder<'a> {
} }
/// Encode the specified struct into a json [u8] /// Encode the specified struct into a json [u8]
pub fn buffer_encode<T:Encodable<Encoder<'a>, io::IoError>>(to_encode_object: &T) -> Vec<u8> { pub fn buffer_encode<
T: serialize::Encodable<Encoder<'a>,
io::IoError>
>(to_encode_object: &T) -> Vec<u8> {
//Serialize the object in a string using a writer //Serialize the object in a string using a writer
let mut m = MemWriter::new(); let mut m = MemWriter::new();
{ {
@@ -618,16 +627,16 @@ impl<'a> Encoder<'a> {
} }
/// Encode the specified struct into a json str /// Encode the specified struct into a json str
pub fn str_encode<T:Encodable<Encoder<'a>, pub fn str_encode<
io::IoError>>( T: serialize::Encodable<Encoder<'a>,
to_encode_object: &T) io::IoError>
-> String { >(to_encode_object: &T) -> String {
let buff = Encoder::buffer_encode(to_encode_object); let buff = Encoder::buffer_encode(to_encode_object);
str::from_utf8(buff.as_slice()).unwrap().to_string() str::from_utf8(buff.as_slice()).unwrap().to_string()
} }
} }
impl<'a> ::Encoder<io::IoError> for Encoder<'a> { impl<'a> serialize::Encoder<io::IoError> for Encoder<'a> {
fn emit_nil(&mut self) -> EncodeResult { write!(self.wr, "null") } fn emit_nil(&mut self) -> EncodeResult { write!(self.wr, "null") }
fn emit_uint(&mut self, v: uint) -> EncodeResult { self.emit_f64(v as f64) } fn emit_uint(&mut self, v: uint) -> EncodeResult { self.emit_f64(v as f64) }
@@ -820,7 +829,7 @@ impl<'a> PrettyEncoder<'a> {
} }
} }
impl<'a> ::Encoder<io::IoError> for PrettyEncoder<'a> { impl<'a> serialize::Encoder<io::IoError> for PrettyEncoder<'a> {
fn emit_nil(&mut self) -> EncodeResult { write!(self.wr, "null") } fn emit_nil(&mut self) -> EncodeResult { write!(self.wr, "null") }
fn emit_uint(&mut self, v: uint) -> EncodeResult { self.emit_f64(v as f64) } fn emit_uint(&mut self, v: uint) -> EncodeResult { self.emit_f64(v as f64) }
@@ -1038,7 +1047,7 @@ impl<'a> ::Encoder<io::IoError> for PrettyEncoder<'a> {
} }
} }
impl<E: ::Encoder<S>, S> Encodable<E, S> for Json { impl<E: serialize::Encoder<S>, S> serialize::Encodable<E, S> for Json {
fn encode(&self, e: &mut E) -> Result<(), S> { fn encode(&self, e: &mut E) -> Result<(), S> {
match *self { match *self {
Number(v) => v.encode(e), Number(v) => v.encode(e),
@@ -1127,8 +1136,8 @@ impl Json {
/// If the Json value is an Object, returns the associated TreeMap. /// If the Json value is an Object, returns the associated TreeMap.
/// Returns None otherwise. /// Returns None otherwise.
pub fn as_object<'a>(&'a self) -> Option<&'a Object> { pub fn as_object<'a>(&'a self) -> Option<&'a Object> {
match self { match *self {
&Object(ref map) => Some(&**map), Object(ref map) => Some(map),
_ => None _ => None
} }
} }
@@ -1141,8 +1150,8 @@ impl Json {
/// If the Json value is a List, returns the associated vector. /// If the Json value is a List, returns the associated vector.
/// Returns None otherwise. /// Returns None otherwise.
pub fn as_list<'a>(&'a self) -> Option<&'a List> { pub fn as_list<'a>(&'a self) -> Option<&'a List> {
match self { match *self {
&List(ref list) => Some(&*list), List(ref list) => Some(list),
_ => None _ => None
} }
} }
@@ -1169,8 +1178,8 @@ impl Json {
/// If the Json value is a Number, returns the associated f64. /// If the Json value is a Number, returns the associated f64.
/// Returns None otherwise. /// Returns None otherwise.
pub fn as_number(&self) -> Option<f64> { pub fn as_number(&self) -> Option<f64> {
match self { match *self {
&Number(n) => Some(n), Number(n) => Some(n),
_ => None _ => None
} }
} }
@@ -1183,8 +1192,8 @@ impl Json {
/// If the Json value is a Boolean, returns the associated bool. /// If the Json value is a Boolean, returns the associated bool.
/// Returns None otherwise. /// Returns None otherwise.
pub fn as_boolean(&self) -> Option<bool> { pub fn as_boolean(&self) -> Option<bool> {
match self { match *self {
&Boolean(b) => Some(b), Boolean(b) => Some(b),
_ => None _ => None
} }
} }
@@ -1197,13 +1206,12 @@ impl Json {
/// If the Json value is a Null, returns (). /// If the Json value is a Null, returns ().
/// Returns None otherwise. /// Returns None otherwise.
pub fn as_null(&self) -> Option<()> { pub fn as_null(&self) -> Option<()> {
match self { match *self {
&Null => Some(()), Null => Some(()),
_ => None _ => None
} }
} }
} }
*/
/* /*
/// The output of the streaming parser. /// The output of the streaming parser.
@@ -1239,6 +1247,7 @@ enum ParserState {
ParseObjectValue, ParseObjectValue,
} }
/*
/// A Stack represents the current position of the parser in the logical /// A Stack represents the current position of the parser in the logical
/// structure of the JSON stream. /// structure of the JSON stream.
/// For example foo.bar[3].x /// For example foo.bar[3].x
@@ -1380,6 +1389,7 @@ impl Stack {
*self.stack.get_mut(len - 1) = InternalIndex(idx); *self.stack.get_mut(len - 1) = InternalIndex(idx);
} }
} }
*/
/// A streaming JSON parser implemented as an iterator of JsonEvent, consuming /// A streaming JSON parser implemented as an iterator of JsonEvent, consuming
/// an iterator of char. /// an iterator of char.
@@ -1857,7 +1867,7 @@ impl<T: Iterator<char>> de::Deserializer<ParserError> for Parser<T> {
#[inline] #[inline]
fn expect_enum_start(&mut self, fn expect_enum_start(&mut self,
token: de::Token, token: de::Token,
name: &str, _name: &str,
variants: &[&str]) -> Result<uint, ParserError> { variants: &[&str]) -> Result<uint, ParserError> {
// It's a little tricky to deserialize enums. Strings are simple to // It's a little tricky to deserialize enums. Strings are simple to
// parse, but objects require us to preparse the entire object because // parse, but objects require us to preparse the entire object because
@@ -1870,7 +1880,7 @@ impl<T: Iterator<char>> de::Deserializer<ParserError> for Parser<T> {
variant variant
} }
de::MapStart(len) => { de::MapStart(_len) => {
let mut variant = None; let mut variant = None;
let mut fields = None; let mut fields = None;
@@ -2029,7 +2039,7 @@ pub fn from_iter<
// Make sure the whole stream has been consumed. // Make sure the whole stream has been consumed.
match parser.next() { match parser.next() {
Some(Ok(token)) => parser.error(TrailingCharacters), Some(Ok(_token)) => parser.error(TrailingCharacters),
Some(Err(err)) => Err(err), Some(Err(err)) => Err(err),
None => Ok(value), None => Ok(value),
} }
@@ -2058,12 +2068,6 @@ impl Decoder {
} }
} }
impl Decoder {
fn pop(&mut self) -> Json {
self.stack.pop().unwrap()
}
}
macro_rules! expect( macro_rules! expect(
($e:expr, Null) => ({ ($e:expr, Null) => ({
match $e { match $e {