Fix serde to compile on master again

This commit is contained in:
Erick Tryzelaar
2014-11-22 16:27:01 -08:00
parent ff8c8c77cc
commit 857723dff6
15 changed files with 1115 additions and 1094 deletions
+10 -2
View File
@@ -13,6 +13,8 @@ use serialize::{Decoder, Decodable};
use serde::de::{Deserializer, Deserialize};
use Animal::{Dog, Frog};
//////////////////////////////////////////////////////////////////////////////
#[deriving(Clone, PartialEq, Show, Decodable)]
@@ -36,7 +38,10 @@ pub enum Error {
mod decoder {
use serialize::Decoder;
use super::{Animal, Dog, Frog, Error, SyntaxError, OtherError};
use super::{Animal, Error};
use super::Animal::{Dog, Frog};
use super::Error::{SyntaxError, OtherError};
use self::State::{AnimalState, IntState, StringState};
enum State {
AnimalState(Animal),
@@ -184,7 +189,10 @@ mod decoder {
//////////////////////////////////////////////////////////////////////////////
mod deserializer {
use super::{Animal, Dog, Frog, Error, EndOfStream, SyntaxError};
use super::{Animal, Error};
use super::Animal::{Dog, Frog};
use super::Error::{EndOfStream, SyntaxError};
use self::State::{AnimalState, IntState, StringState, EndState};
use serde::de;
+42 -42
View File
@@ -456,13 +456,13 @@ impl Log {
Log {
timestamp: 2837513946597,
zone_id: 123456,
zone_plan: FREE,
zone_plan: ZonePlan::FREE,
http: Http {
protocol: HTTP11,
protocol: HttpProtocol::HTTP11,
status: 200,
host_status: 503,
up_status: 520,
method: GET,
method: HttpMethod::GET,
content_type: "text/html".to_string(),
user_agent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36".to_string(),
referer: "https://www.cloudflare.com/".to_string(),
@@ -472,10 +472,10 @@ impl Log {
ip: "1.2.3.4".to_string(),
port: 8000,
hostname: "www.example.com".to_string(),
protocol: HTTPS,
protocol: OriginProtocol::HTTPS,
},
country: US,
cache_status: Hit,
country: Country::US,
cache_status: CacheStatus::Hit,
server_ip: "192.168.1.1".to_string(),
server_name: "metal.cloudflare.com".to_string(),
remote_ip: "10.1.2.3".to_string(),
@@ -673,58 +673,58 @@ fn bench_copy(b: &mut Bencher) {
fn manual_no_escape<W: Writer>(mut wr: W, log: &Log) {
wr.write_str("{\"timestamp\":").unwrap();
(write!(wr, "{}", log.timestamp)).unwrap();
(write!(&mut wr, "{}", log.timestamp)).unwrap();
wr.write_str(",\"zone_id\":").unwrap();
(write!(wr, "{}", log.zone_id)).unwrap();
(write!(&mut wr, "{}", log.zone_id)).unwrap();
wr.write_str(",\"zone_plan\":").unwrap();
(write!(wr, "{}", log.zone_plan as uint)).unwrap();
(write!(&mut wr, "{}", log.zone_plan as uint)).unwrap();
wr.write_str(",\"http\":{\"protocol\":").unwrap();
(write!(wr, "{}", log.http.protocol as uint)).unwrap();
(write!(&mut wr, "{}", log.http.protocol as uint)).unwrap();
wr.write_str(",\"status\":").unwrap();
(write!(wr, "{}", log.http.status)).unwrap();
(write!(&mut wr, "{}", log.http.status)).unwrap();
wr.write_str(",\"host_status\":").unwrap();
(write!(wr, "{}", log.http.host_status)).unwrap();
(write!(&mut wr, "{}", log.http.host_status)).unwrap();
wr.write_str(",\"up_status\":").unwrap();
(write!(wr, "{}", log.http.up_status)).unwrap();
(write!(&mut wr, "{}", log.http.up_status)).unwrap();
wr.write_str(",\"method\":").unwrap();
(write!(wr, "{}", log.http.method as uint)).unwrap();
(write!(&mut wr, "{}", log.http.method as uint)).unwrap();
wr.write_str(",\"content_type\":").unwrap();
(write!(wr, "\"{}\"", log.http.content_type)).unwrap();
(write!(&mut wr, "\"{}\"", log.http.content_type)).unwrap();
wr.write_str(",\"user_agent\":").unwrap();
(write!(wr, "\"{}\"", log.http.user_agent)).unwrap();
(write!(&mut wr, "\"{}\"", log.http.user_agent)).unwrap();
wr.write_str(",\"referer\":").unwrap();
(write!(wr, "\"{}\"", log.http.referer)).unwrap();
(write!(&mut wr, "\"{}\"", log.http.referer)).unwrap();
wr.write_str(",\"request_uri\":").unwrap();
(write!(wr, "\"{}\"", log.http.request_uri)).unwrap();
(write!(&mut wr, "\"{}\"", log.http.request_uri)).unwrap();
wr.write_str("},\"origin\":{").unwrap();
wr.write_str("\"ip\":").unwrap();
(write!(wr, "\"{}\"", log.origin.ip)).unwrap();
(write!(&mut wr, "\"{}\"", log.origin.ip)).unwrap();
wr.write_str(",\"port\":").unwrap();
(write!(wr, "{}", log.origin.port)).unwrap();
(write!(&mut wr, "{}", log.origin.port)).unwrap();
wr.write_str(",\"hostname\":").unwrap();
(write!(wr, "\"{}\"", log.origin.hostname)).unwrap();
(write!(&mut wr, "\"{}\"", log.origin.hostname)).unwrap();
wr.write_str(",\"protocol\":").unwrap();
(write!(wr, "{}", log.origin.protocol as uint)).unwrap();
(write!(&mut wr, "{}", log.origin.protocol as uint)).unwrap();
wr.write_str("},\"country\":").unwrap();
(write!(wr, "{}", log.country as uint)).unwrap();
(write!(&mut wr, "{}", log.country as uint)).unwrap();
wr.write_str(",\"cache_status\":").unwrap();
(write!(wr, "{}", log.cache_status as uint)).unwrap();
(write!(&mut wr, "{}", log.cache_status as uint)).unwrap();
wr.write_str(",\"server_ip\":").unwrap();
(write!(wr, "\"{}\"", log.server_ip)).unwrap();
(write!(&mut wr, "\"{}\"", log.server_ip)).unwrap();
wr.write_str(",\"server_name\":").unwrap();
(write!(wr, "\"{}\"", log.server_name)).unwrap();
(write!(&mut wr, "\"{}\"", log.server_name)).unwrap();
wr.write_str(",\"remote_ip\":").unwrap();
(write!(wr, "\"{}\"", log.remote_ip)).unwrap();
(write!(&mut wr, "\"{}\"", log.remote_ip)).unwrap();
wr.write_str(",\"bytes_dlv\":").unwrap();
(write!(wr, "{}", log.bytes_dlv)).unwrap();
(write!(&mut wr, "{}", log.bytes_dlv)).unwrap();
wr.write_str(",\"ray_id\":").unwrap();
(write!(wr, "\"{}\"", log.ray_id)).unwrap();
(write!(&mut wr, "\"{}\"", log.ray_id)).unwrap();
wr.write_str("}").unwrap();
}
@@ -732,38 +732,38 @@ fn manual_escape<W: Writer>(mut wr: W, log: &Log) {
wr.write_str("{").unwrap();
escape_str(&mut wr, "timestamp").unwrap();
wr.write_str(":").unwrap();
(write!(wr, "{}", log.timestamp)).unwrap();
(write!(&mut wr, "{}", log.timestamp)).unwrap();
wr.write_str(",").unwrap();
escape_str(&mut wr, "zone_id").unwrap();
wr.write_str(":").unwrap();
(write!(wr, "{}", log.zone_id)).unwrap();
(write!(&mut wr, "{}", log.zone_id)).unwrap();
wr.write_str(",").unwrap();
escape_str(&mut wr, "zone_plan").unwrap();
wr.write_str(":").unwrap();
(write!(wr, "{}", log.zone_plan as int)).unwrap();
(write!(&mut wr, "{}", log.zone_plan as int)).unwrap();
wr.write_str(",").unwrap();
escape_str(&mut wr, "http").unwrap();
wr.write_str(":{").unwrap();
escape_str(&mut wr, "protocol").unwrap();
wr.write_str(":").unwrap();
(write!(wr, "{}", log.http.protocol as uint)).unwrap();
(write!(&mut wr, "{}", log.http.protocol as uint)).unwrap();
wr.write_str(",").unwrap();
escape_str(&mut wr, "status").unwrap();
wr.write_str(":").unwrap();
(write!(wr, "{}", log.http.status)).unwrap();
(write!(&mut wr, "{}", log.http.status)).unwrap();
wr.write_str(",").unwrap();
escape_str(&mut wr, "host_status").unwrap();
wr.write_str(":").unwrap();
(write!(wr, "{}", log.http.host_status)).unwrap();
(write!(&mut wr, "{}", log.http.host_status)).unwrap();
wr.write_str(",").unwrap();
escape_str(&mut wr, "up_status").unwrap();
wr.write_str(":").unwrap();
(write!(wr, "{}", log.http.up_status)).unwrap();
(write!(&mut wr, "{}", log.http.up_status)).unwrap();
wr.write_str(",").unwrap();
escape_str(&mut wr, "method").unwrap();
wr.write_str(":").unwrap();
(write!(wr, "{}", log.http.method as uint)).unwrap();
(write!(&mut wr, "{}", log.http.method as uint)).unwrap();
wr.write_str(",").unwrap();
escape_str(&mut wr, "content_type").unwrap();
wr.write_str(":").unwrap();
@@ -791,7 +791,7 @@ fn manual_escape<W: Writer>(mut wr: W, log: &Log) {
wr.write_str(",").unwrap();
escape_str(&mut wr, "port").unwrap();
wr.write_str(":").unwrap();
(write!(wr, "{}", log.origin.port)).unwrap();
(write!(&mut wr, "{}", log.origin.port)).unwrap();
wr.write_str(",").unwrap();
escape_str(&mut wr, "hostname").unwrap();
wr.write_str(":").unwrap();
@@ -799,16 +799,16 @@ fn manual_escape<W: Writer>(mut wr: W, log: &Log) {
wr.write_str(",").unwrap();
escape_str(&mut wr, "protocol").unwrap();
wr.write_str(":").unwrap();
(write!(wr, "{}", log.origin.protocol as uint)).unwrap();
(write!(&mut wr, "{}", log.origin.protocol as uint)).unwrap();
wr.write_str("},").unwrap();
escape_str(&mut wr, "country").unwrap();
wr.write_str(":").unwrap();
(write!(wr, "{}", log.country as uint)).unwrap();
(write!(&mut wr, "{}", log.country as uint)).unwrap();
wr.write_str(",").unwrap();
escape_str(&mut wr, "cache_status").unwrap();
wr.write_str(":").unwrap();
(write!(wr, "{}", log.cache_status as uint)).unwrap();
(write!(&mut wr, "{}", log.cache_status as uint)).unwrap();
wr.write_str(",").unwrap();
escape_str(&mut wr, "server_ip").unwrap();
wr.write_str(":").unwrap();
@@ -824,7 +824,7 @@ fn manual_escape<W: Writer>(mut wr: W, log: &Log) {
wr.write_str(",").unwrap();
escape_str(&mut wr, "bytes_dlv").unwrap();
wr.write_str(":").unwrap();
(write!(wr, "{}", log.bytes_dlv)).unwrap();
(write!(&mut wr, "{}", log.bytes_dlv)).unwrap();
wr.write_str(",").unwrap();
escape_str(&mut wr, "ray_id").unwrap();
+6 -2
View File
@@ -31,7 +31,9 @@ mod decoder {
use std::collections::hash_map::MoveEntries;
use serialize;
use super::{Error, EndOfStream, SyntaxError, OtherError};
use super::Error;
use super::Error::{EndOfStream, SyntaxError, OtherError};
use self::Value::{StringValue, IntValue};
enum Value {
StringValue(String),
@@ -172,7 +174,9 @@ mod deserializer {
use std::collections::HashMap;
use std::collections::hash_map::MoveEntries;
use super::{Error, EndOfStream, SyntaxError};
use super::Error;
use super::Error::{EndOfStream, SyntaxError};
use self::State::{StartState, KeyOrEndState, ValueState, EndState};
use serde::de;
+69 -42
View File
@@ -48,7 +48,20 @@ mod decoder {
use std::collections::HashMap;
use serialize::Decoder;
use super::{Outer, Inner, Error, SyntaxError, OtherError};
use super::{Outer, Inner, Error};
use self::State::{
OuterState,
InnerState,
NullState,
UintState,
CharState,
StringState,
FieldState,
VecState,
MapState,
OptionState,
};
#[deriving(Show)]
enum State {
@@ -80,7 +93,7 @@ mod decoder {
impl Decoder<Error> for OuterDecoder {
fn error(&mut self, msg: &str) -> Error {
OtherError(msg.to_string())
Error::OtherError(msg.to_string())
}
// Primitive types:
@@ -88,64 +101,64 @@ mod decoder {
fn read_nil(&mut self) -> Result<(), Error> {
match self.stack.pop() {
Some(NullState) => Ok(()),
_ => Err(SyntaxError("NullState".to_string())),
_ => Err(Error::SyntaxError("NullState".to_string())),
}
}
#[inline]
fn read_uint(&mut self) -> Result<uint, Error> {
match self.stack.pop() {
Some(UintState(value)) => Ok(value),
_ => Err(SyntaxError("UintState".to_string())),
_ => Err(Error::SyntaxError("UintState".to_string())),
}
}
fn read_u64(&mut self) -> Result<u64, Error> { Err(SyntaxError("".to_string())) }
fn read_u32(&mut self) -> Result<u32, Error> { Err(SyntaxError("".to_string())) }
fn read_u16(&mut self) -> Result<u16, Error> { Err(SyntaxError("".to_string())) }
fn read_u8(&mut self) -> Result<u8, Error> { Err(SyntaxError("".to_string())) }
fn read_int(&mut self) -> Result<int, Error> { Err(SyntaxError("".to_string())) }
fn read_i64(&mut self) -> Result<i64, Error> { Err(SyntaxError("".to_string())) }
fn read_i32(&mut self) -> Result<i32, Error> { Err(SyntaxError("".to_string())) }
fn read_i16(&mut self) -> Result<i16, Error> { Err(SyntaxError("".to_string())) }
fn read_i8(&mut self) -> Result<i8, Error> { Err(SyntaxError("".to_string())) }
fn read_bool(&mut self) -> Result<bool, Error> { Err(SyntaxError("".to_string())) }
fn read_f64(&mut self) -> Result<f64, Error> { Err(SyntaxError("".to_string())) }
fn read_f32(&mut self) -> Result<f32, Error> { Err(SyntaxError("".to_string())) }
fn read_u64(&mut self) -> Result<u64, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_u32(&mut self) -> Result<u32, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_u16(&mut self) -> Result<u16, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_u8(&mut self) -> Result<u8, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_int(&mut self) -> Result<int, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_i64(&mut self) -> Result<i64, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_i32(&mut self) -> Result<i32, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_i16(&mut self) -> Result<i16, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_i8(&mut self) -> Result<i8, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_bool(&mut self) -> Result<bool, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_f64(&mut self) -> Result<f64, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_f32(&mut self) -> Result<f32, Error> { Err(Error::SyntaxError("".to_string())) }
#[inline]
fn read_char(&mut self) -> Result<char, Error> {
match self.stack.pop() {
Some(CharState(c)) => Ok(c),
_ => Err(SyntaxError("".to_string())),
_ => Err(Error::SyntaxError("".to_string())),
}
}
#[inline]
fn read_str(&mut self) -> Result<String, Error> {
match self.stack.pop() {
Some(StringState(value)) => Ok(value),
_ => Err(SyntaxError("".to_string())),
_ => Err(Error::SyntaxError("".to_string())),
}
}
// Compound types:
fn read_enum<T>(&mut self, _name: &str, _f: |&mut OuterDecoder| -> Result<T, Error>) -> Result<T, Error> { Err(SyntaxError("".to_string())) }
fn read_enum<T>(&mut self, _name: &str, _f: |&mut OuterDecoder| -> Result<T, Error>) -> Result<T, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_enum_variant<T>(&mut self,
_names: &[&str],
_f: |&mut OuterDecoder, uint| -> Result<T, Error>)
-> Result<T, Error> { Err(SyntaxError("".to_string())) }
-> Result<T, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_enum_variant_arg<T>(&mut self,
_a_idx: uint,
_f: |&mut OuterDecoder| -> Result<T, Error>)
-> Result<T, Error> { Err(SyntaxError("".to_string())) }
-> Result<T, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_enum_struct_variant<T>(&mut self,
_names: &[&str],
_f: |&mut OuterDecoder, uint| -> Result<T, Error>)
-> Result<T, Error> { Err(SyntaxError("".to_string())) }
-> Result<T, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_enum_struct_variant_field<T>(&mut self,
_f_name: &str,
_f_idx: uint,
_f: |&mut OuterDecoder| -> Result<T, Error>)
-> Result<T, Error> { Err(SyntaxError("".to_string())) }
-> Result<T, Error> { Err(Error::SyntaxError("".to_string())) }
#[inline]
fn read_struct<T>(&mut self, s_name: &str, _len: uint, f: |&mut OuterDecoder| -> Result<T, Error>) -> Result<T, Error> {
@@ -156,7 +169,7 @@ mod decoder {
self.stack.push(FieldState("inner"));
f(self)
} else {
Err(SyntaxError("expected Outer".to_string()))
Err(Error::SyntaxError("expected Outer".to_string()))
}
}
Some(InnerState(Inner { a: (), b, c })) => {
@@ -171,10 +184,10 @@ mod decoder {
self.stack.push(FieldState("a"));
f(self)
} else {
Err(SyntaxError("expected Inner".to_string()))
Err(Error::SyntaxError("expected Inner".to_string()))
}
}
_ => Err(SyntaxError("expected InnerState or OuterState".to_string())),
_ => Err(Error::SyntaxError("expected InnerState or OuterState".to_string())),
}
}
#[inline]
@@ -184,32 +197,32 @@ mod decoder {
if f_name == name {
f(self)
} else {
Err(SyntaxError("expected FieldState".to_string()))
Err(Error::SyntaxError("expected FieldState".to_string()))
}
}
_ => Err(SyntaxError("expected FieldState".to_string()))
_ => Err(Error::SyntaxError("expected FieldState".to_string()))
}
}
fn read_tuple<T>(&mut self, _len: uint, _f: |&mut OuterDecoder| -> Result<T, Error>) -> Result<T, Error> { Err(SyntaxError("".to_string())) }
fn read_tuple_arg<T>(&mut self, _a_idx: uint, _f: |&mut OuterDecoder| -> Result<T, Error>) -> Result<T, Error> { Err(SyntaxError("".to_string())) }
fn read_tuple<T>(&mut self, _len: uint, _f: |&mut OuterDecoder| -> Result<T, Error>) -> Result<T, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_tuple_arg<T>(&mut self, _a_idx: uint, _f: |&mut OuterDecoder| -> Result<T, Error>) -> Result<T, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_tuple_struct<T>(&mut self,
_s_name: &str,
_len: uint,
_f: |&mut OuterDecoder| -> Result<T, Error>)
-> Result<T, Error> { Err(SyntaxError("".to_string())) }
-> Result<T, Error> { Err(Error::SyntaxError("".to_string())) }
fn read_tuple_struct_arg<T>(&mut self,
_a_idx: uint,
_f: |&mut OuterDecoder| -> Result<T, Error>)
-> Result<T, Error> { Err(SyntaxError("".to_string())) }
-> Result<T, Error> { Err(Error::SyntaxError("".to_string())) }
// Specialized types:
#[inline]
fn read_option<T>(&mut self, f: |&mut OuterDecoder, bool| -> Result<T, Error>) -> Result<T, Error> {
match self.stack.pop() {
Some(OptionState(b)) => f(self, b),
_ => Err(SyntaxError("expected OptionState".to_string())),
_ => Err(Error::SyntaxError("expected OptionState".to_string())),
}
}
@@ -223,7 +236,7 @@ mod decoder {
}
f(self, len)
}
_ => Err(SyntaxError("expected VecState".to_string()))
_ => Err(Error::SyntaxError("expected VecState".to_string()))
}
}
#[inline]
@@ -250,7 +263,7 @@ mod decoder {
}
f(self, len)
}
_ => Err(SyntaxError("expected MapState".to_string())),
_ => Err(Error::SyntaxError("expected MapState".to_string())),
}
}
#[inline]
@@ -269,9 +282,24 @@ mod decoder {
mod deserializer {
use std::collections::HashMap;
use super::{Outer, Inner};
use super::{Error, EndOfStream, SyntaxError, UnexpectedName, MissingField};
use super::Error;
use serde::de;
use self::State::{
OuterState,
InnerState,
FieldState,
NullState,
UintState,
CharState,
StringState,
OptionState,
//TupleState(uint),
VecState,
MapState,
EndState,
};
#[deriving(Show)]
enum State {
OuterState(Outer),
@@ -286,7 +314,6 @@ mod deserializer {
VecState(Vec<Inner>),
MapState(HashMap<String, Option<char>>),
EndState,
}
pub struct OuterDeserializer {
@@ -367,29 +394,29 @@ mod deserializer {
impl de::Deserializer<Error> for OuterDeserializer {
#[inline]
fn end_of_stream_error(&mut self) -> Error {
EndOfStream
Error::EndOfStream
}
#[inline]
fn syntax_error(&mut self, token: de::Token, expected: &[de::TokenKind]) -> Error {
SyntaxError(format!("expected {}, found {}", expected, token))
Error::SyntaxError(format!("expected {}, found {}", expected, token))
}
#[inline]
fn unexpected_name_error(&mut self, token: de::Token) -> Error {
UnexpectedName(format!("found {}", token))
Error::UnexpectedName(format!("found {}", token))
}
#[inline]
fn conversion_error(&mut self, token: de::Token) -> Error {
UnexpectedName(format!("found {}", token))
Error::UnexpectedName(format!("found {}", token))
}
#[inline]
fn missing_field<
T: de::Deserialize<OuterDeserializer, Error>
>(&mut self, field: &'static str) -> Result<T, Error> {
Err(MissingField(field))
Err(Error::MissingField(field))
}
}
}
+5 -2
View File
@@ -29,7 +29,8 @@ mod decoder {
use std::vec;
use serialize;
use super::{Error, EndOfStream, SyntaxError, OtherError};
use super::Error;
use super::Error::{EndOfStream, SyntaxError, OtherError};
pub struct IntDecoder {
len: uint,
@@ -250,7 +251,9 @@ mod deserializer {
//use std::num;
use std::vec;
use super::{Error, EndOfStream, SyntaxError};
use super::Error;
use super::Error::{EndOfStream, SyntaxError};
use self::State::{StartState, SepOrEndState, EndState};
use serde::de;