Merge pull request #18 from tomprogrammer/rust-head
Update to rust nightly
This commit is contained in:
commit
4ca70c1396
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
/target/
|
||||
/Cargo.lock
|
||||
/serde2/Cargo.lock
|
||||
|
@ -17,16 +17,16 @@ use Animal::{Dog, Frog};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Clone, PartialEq, Show, RustcDecodable)]
|
||||
#[derive(Clone, PartialEq, Debug, RustcDecodable)]
|
||||
#[derive_deserialize]
|
||||
enum Animal {
|
||||
Dog,
|
||||
Frog(String, int)
|
||||
Frog(String, isize)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Show)]
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
EndOfStream,
|
||||
SyntaxError,
|
||||
@ -41,11 +41,11 @@ mod decoder {
|
||||
use super::{Animal, Error};
|
||||
use super::Animal::{Dog, Frog};
|
||||
use super::Error::{SyntaxError, OtherError};
|
||||
use self::State::{AnimalState, IntState, StringState};
|
||||
use self::State::{AnimalState, IsizeState, StringState};
|
||||
|
||||
enum State {
|
||||
AnimalState(Animal),
|
||||
IntState(int),
|
||||
IsizeState(isize),
|
||||
StringState(String),
|
||||
}
|
||||
|
||||
@ -72,15 +72,15 @@ mod decoder {
|
||||
|
||||
// Primitive types:
|
||||
fn read_nil(&mut self) -> Result<(), Error> { Err(SyntaxError) }
|
||||
fn read_usize(&mut self) -> Result<uint, Error> { Err(SyntaxError) }
|
||||
fn read_usize(&mut self) -> Result<usize, Error> { Err(SyntaxError) }
|
||||
fn read_u64(&mut self) -> Result<u64, Error> { Err(SyntaxError) }
|
||||
fn read_u32(&mut self) -> Result<u32, Error> { Err(SyntaxError) }
|
||||
fn read_u16(&mut self) -> Result<u16, Error> { Err(SyntaxError) }
|
||||
fn read_u8(&mut self) -> Result<u8, Error> { Err(SyntaxError) }
|
||||
#[inline]
|
||||
fn read_isize(&mut self) -> Result<int, Error> {
|
||||
fn read_isize(&mut self) -> Result<isize, Error> {
|
||||
match self.stack.pop() {
|
||||
Some(IntState(x)) => Ok(x),
|
||||
Some(IsizeState(x)) => Ok(x),
|
||||
_ => Err(SyntaxError),
|
||||
}
|
||||
}
|
||||
@ -120,12 +120,12 @@ mod decoder {
|
||||
|
||||
#[inline]
|
||||
fn read_enum_variant<T, F>(&mut self, names: &[&str], f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut AnimalDecoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut AnimalDecoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
let name = match self.stack.pop() {
|
||||
Some(AnimalState(Dog)) => "Dog",
|
||||
Some(AnimalState(Frog(x0, x1))) => {
|
||||
self.stack.push(IntState(x1));
|
||||
self.stack.push(IsizeState(x1));
|
||||
self.stack.push(StringState(x0));
|
||||
"Frog"
|
||||
}
|
||||
@ -141,55 +141,55 @@ mod decoder {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn read_enum_variant_arg<T, F>(&mut self, _a_idx: uint, f: F) -> Result<T, Error> where
|
||||
fn read_enum_variant_arg<T, F>(&mut self, _a_idx: usize, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut AnimalDecoder) -> Result<T, Error>,
|
||||
{
|
||||
f(self)
|
||||
}
|
||||
|
||||
fn read_enum_struct_variant<T, F>(&mut self, _names: &[&str], _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut AnimalDecoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut AnimalDecoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_enum_struct_variant_field<T, F>(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_enum_struct_variant_field<T, F>(&mut self, _f_name: &str, _f_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut AnimalDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_struct<T, F>(&mut self, _s_name: &str, _len: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_struct<T, F>(&mut self, _s_name: &str, _len: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut AnimalDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_struct_field<T, F>(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_struct_field<T, F>(&mut self, _f_name: &str, _f_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut AnimalDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_tuple<T, F>(&mut self, _len: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_tuple<T, F>(&mut self, _len: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut AnimalDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_tuple_arg<T, F>(&mut self, _a_idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_tuple_arg<T, F>(&mut self, _a_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut AnimalDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_tuple_struct<T, F>(&mut self, _s_name: &str, _len: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_tuple_struct<T, F>(&mut self, _s_name: &str, _len: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut AnimalDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_tuple_struct_arg<T, F>(&mut self, _a_idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_tuple_struct_arg<T, F>(&mut self, _a_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut AnimalDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
@ -204,31 +204,31 @@ mod decoder {
|
||||
|
||||
#[inline]
|
||||
fn read_seq<T, F>(&mut self, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut AnimalDecoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut AnimalDecoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
f(self, 3)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn read_seq_elt<T, F>(&mut self, _idx: uint, f: F) -> Result<T, Error> where
|
||||
fn read_seq_elt<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut AnimalDecoder) -> Result<T, Error>,
|
||||
{
|
||||
f(self)
|
||||
}
|
||||
|
||||
fn read_map<T, F>(&mut self, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut AnimalDecoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut AnimalDecoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
Err(SyntaxError)
|
||||
}
|
||||
|
||||
fn read_map_elt_key<T, F>(&mut self, _idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_map_elt_key<T, F>(&mut self, _idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut AnimalDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(SyntaxError)
|
||||
}
|
||||
|
||||
fn read_map_elt_val<T, F>(&mut self, _idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_map_elt_val<T, F>(&mut self, _idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut AnimalDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(SyntaxError)
|
||||
@ -242,13 +242,13 @@ mod deserializer {
|
||||
use super::{Animal, Error};
|
||||
use super::Animal::{Dog, Frog};
|
||||
use super::Error::{EndOfStream, SyntaxError};
|
||||
use self::State::{AnimalState, IntState, StringState, EndState};
|
||||
use self::State::{AnimalState, IsizeState, StringState, EndState};
|
||||
|
||||
use serde::de;
|
||||
|
||||
enum State {
|
||||
AnimalState(Animal),
|
||||
IntState(int),
|
||||
IsizeState(isize),
|
||||
StringState(String),
|
||||
EndState,
|
||||
|
||||
@ -279,12 +279,12 @@ mod deserializer {
|
||||
}
|
||||
Some(AnimalState(Frog(x0, x1))) => {
|
||||
self.stack.push(EndState);
|
||||
self.stack.push(IntState(x1));
|
||||
self.stack.push(IsizeState(x1));
|
||||
self.stack.push(StringState(x0));
|
||||
Some(Ok(de::Token::EnumStart("Animal", "Frog", 2)))
|
||||
}
|
||||
Some(IntState(x)) => {
|
||||
Some(Ok(de::Token::Int(x)))
|
||||
Some(IsizeState(x)) => {
|
||||
Some(Ok(de::Token::Isize(x)))
|
||||
}
|
||||
Some(StringState(x)) => {
|
||||
Some(Ok(de::Token::String(x)))
|
||||
|
176
benches/bench_log.rs
Normal file → Executable file
176
benches/bench_log.rs
Normal file → Executable file
@ -1,4 +1,4 @@
|
||||
#![feature(plugin)]
|
||||
#![feature(plugin, io)]
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
#[plugin]
|
||||
@ -8,9 +8,9 @@ extern crate serde;
|
||||
extern crate "rustc-serialize" as rustc_serialize;
|
||||
extern crate test;
|
||||
|
||||
use std::io::ByRefWriter;
|
||||
use std::io::extensions::Bytes;
|
||||
use std::io;
|
||||
use std::old_io::ByRefWriter;
|
||||
use std::old_io::extensions::Bytes;
|
||||
use std::old_io;
|
||||
use std::num::FromPrimitive;
|
||||
use test::Bencher;
|
||||
|
||||
@ -22,7 +22,7 @@ use serde::ser;
|
||||
|
||||
use rustc_serialize::Encodable;
|
||||
|
||||
#[derive(Show, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
#[derive(Debug, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
#[derive_serialize]
|
||||
#[derive_deserialize]
|
||||
struct Http {
|
||||
@ -37,7 +37,7 @@ struct Http {
|
||||
request_uri: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Show, PartialEq, FromPrimitive)]
|
||||
#[derive(Copy, Debug, PartialEq, FromPrimitive)]
|
||||
enum HttpProtocol {
|
||||
HTTP_PROTOCOL_UNKNOWN,
|
||||
HTTP10,
|
||||
@ -46,7 +46,7 @@ enum HttpProtocol {
|
||||
|
||||
impl rustc_serialize::Encodable for HttpProtocol {
|
||||
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
(*self as uint).encode(s)
|
||||
(*self as usize).encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ impl rustc_serialize::Decodable for HttpProtocol {
|
||||
impl<S: ser::Serializer<E>, E> ser::Serialize<S, E> for HttpProtocol {
|
||||
#[inline]
|
||||
fn serialize(&self, s: &mut S) -> Result<(), E> {
|
||||
s.serialize_uint(*self as uint)
|
||||
s.serialize_usize(*self as usize)
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ impl<D: de::Deserializer<E>, E> de::Deserialize<D, E> for HttpProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Show, PartialEq, FromPrimitive)]
|
||||
#[derive(Copy, Debug, PartialEq, FromPrimitive)]
|
||||
enum HttpMethod {
|
||||
METHOD_UNKNOWN,
|
||||
GET,
|
||||
@ -90,7 +90,7 @@ enum HttpMethod {
|
||||
|
||||
impl rustc_serialize::Encodable for HttpMethod {
|
||||
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
(*self as uint).encode(s)
|
||||
(*self as usize).encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ impl rustc_serialize::Decodable for HttpMethod {
|
||||
fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<HttpMethod, D::Error> {
|
||||
match FromPrimitive::from_uint(try!(d.read_usize())) {
|
||||
Some(value) => Ok(value),
|
||||
None => Err(d.error("cannot convert from uint")),
|
||||
None => Err(d.error("cannot convert from usize")),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,7 +106,7 @@ impl rustc_serialize::Decodable for HttpMethod {
|
||||
impl<S: ser::Serializer<E>, E> ser::Serialize<S, E> for HttpMethod {
|
||||
#[inline]
|
||||
fn serialize(&self, s: &mut S) -> Result<(), E> {
|
||||
s.serialize_uint(*self as uint)
|
||||
s.serialize_usize(*self as usize)
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ impl<D: de::Deserializer<E>, E> de::Deserialize<D, E> for HttpMethod {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Show, PartialEq, FromPrimitive)]
|
||||
#[derive(Copy, Debug, PartialEq, FromPrimitive)]
|
||||
enum CacheStatus {
|
||||
CACHESTATUS_UNKNOWN,
|
||||
Miss,
|
||||
@ -127,7 +127,7 @@ enum CacheStatus {
|
||||
|
||||
impl rustc_serialize::Encodable for CacheStatus {
|
||||
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
(*self as uint).encode(s)
|
||||
(*self as usize).encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ impl rustc_serialize::Decodable for CacheStatus {
|
||||
fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<CacheStatus, D::Error> {
|
||||
match FromPrimitive::from_uint(try!(d.read_usize())) {
|
||||
Some(value) => Ok(value),
|
||||
None => Err(d.error("cannot convert from uint")),
|
||||
None => Err(d.error("cannot convert from usize")),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -143,7 +143,7 @@ impl rustc_serialize::Decodable for CacheStatus {
|
||||
impl<S: ser::Serializer<E>, E> ser::Serialize<S, E> for CacheStatus {
|
||||
#[inline]
|
||||
fn serialize(&self, s: &mut S) -> Result<(), E> {
|
||||
s.serialize_uint(*self as uint)
|
||||
s.serialize_usize(*self as usize)
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,7 +154,7 @@ impl<D: de::Deserializer<E>, E> de::Deserialize<D, E> for CacheStatus {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Show, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
#[derive(Debug, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
#[derive_serialize]
|
||||
#[derive_deserialize]
|
||||
struct Origin {
|
||||
@ -164,7 +164,7 @@ struct Origin {
|
||||
protocol: OriginProtocol,
|
||||
}
|
||||
|
||||
#[derive(Copy, Show, PartialEq, FromPrimitive)]
|
||||
#[derive(Copy, Debug, PartialEq, FromPrimitive)]
|
||||
enum OriginProtocol {
|
||||
ORIGIN_PROTOCOL_UNKNOWN,
|
||||
HTTP,
|
||||
@ -173,7 +173,7 @@ enum OriginProtocol {
|
||||
|
||||
impl rustc_serialize::Encodable for OriginProtocol {
|
||||
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
(*self as uint).encode(s)
|
||||
(*self as usize).encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,7 +181,7 @@ impl rustc_serialize::Decodable for OriginProtocol {
|
||||
fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<OriginProtocol, D::Error> {
|
||||
match FromPrimitive::from_uint(try!(d.read_usize())) {
|
||||
Some(value) => Ok(value),
|
||||
None => Err(d.error("cannot convert from uint")),
|
||||
None => Err(d.error("cannot convert from usize")),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -189,7 +189,7 @@ impl rustc_serialize::Decodable for OriginProtocol {
|
||||
impl<S: ser::Serializer<E>, E> ser::Serialize<S, E> for OriginProtocol {
|
||||
#[inline]
|
||||
fn serialize(&self, s: &mut S) -> Result<(), E> {
|
||||
s.serialize_uint(*self as uint)
|
||||
s.serialize_usize(*self as usize)
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ impl<D: de::Deserializer<E>, E> de::Deserialize<D, E> for OriginProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Show, PartialEq, FromPrimitive)]
|
||||
#[derive(Copy, Debug, PartialEq, FromPrimitive)]
|
||||
enum ZonePlan {
|
||||
ZONEPLAN_UNKNOWN,
|
||||
FREE,
|
||||
@ -211,7 +211,7 @@ enum ZonePlan {
|
||||
|
||||
impl rustc_serialize::Encodable for ZonePlan {
|
||||
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
(*self as uint).encode(s)
|
||||
(*self as usize).encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
@ -219,7 +219,7 @@ impl rustc_serialize::Decodable for ZonePlan {
|
||||
fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<ZonePlan, D::Error> {
|
||||
match FromPrimitive::from_uint(try!(d.read_usize())) {
|
||||
Some(value) => Ok(value),
|
||||
None => Err(d.error("cannot convert from uint")),
|
||||
None => Err(d.error("cannot convert from usize")),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -227,7 +227,7 @@ impl rustc_serialize::Decodable for ZonePlan {
|
||||
impl<S: ser::Serializer<E>, E> ser::Serialize<S, E> for ZonePlan {
|
||||
#[inline]
|
||||
fn serialize(&self, s: &mut S) -> Result<(), E> {
|
||||
s.serialize_uint(*self as uint)
|
||||
s.serialize_usize(*self as usize)
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,7 +238,7 @@ impl<D: de::Deserializer<E>, E> de::Deserialize<D, E> for ZonePlan {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Show, PartialEq, FromPrimitive)]
|
||||
#[derive(Copy, Debug, PartialEq, FromPrimitive)]
|
||||
enum Country {
|
||||
UNKNOWN,
|
||||
A1,
|
||||
@ -500,7 +500,7 @@ enum Country {
|
||||
|
||||
impl rustc_serialize::Encodable for Country {
|
||||
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
(*self as uint).encode(s)
|
||||
(*self as usize).encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
@ -508,7 +508,7 @@ impl rustc_serialize::Decodable for Country {
|
||||
fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<Country, D::Error> {
|
||||
match FromPrimitive::from_uint(try!(d.read_usize())) {
|
||||
Some(value) => Ok(value),
|
||||
None => Err(d.error("cannot convert from uint")),
|
||||
None => Err(d.error("cannot convert from usize")),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -516,7 +516,7 @@ impl rustc_serialize::Decodable for Country {
|
||||
impl<S: ser::Serializer<E>, E> ser::Serialize<S, E> for Country {
|
||||
#[inline]
|
||||
fn serialize(&self, s: &mut S) -> Result<(), E> {
|
||||
s.serialize_uint(*self as uint)
|
||||
s.serialize_usize(*self as usize)
|
||||
}
|
||||
}
|
||||
|
||||
@ -527,7 +527,7 @@ impl<D: de::Deserializer<E>, E> de::Deserialize<D, E> for Country {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Show, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
#[derive(Debug, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
#[derive_serialize]
|
||||
#[derive_deserialize]
|
||||
struct Log {
|
||||
@ -610,7 +610,7 @@ struct MyMemWriter0 {
|
||||
}
|
||||
|
||||
impl MyMemWriter0 {
|
||||
pub fn with_capacity(cap: uint) -> MyMemWriter0 {
|
||||
pub fn with_capacity(cap: usize) -> MyMemWriter0 {
|
||||
MyMemWriter0 {
|
||||
buf: Vec::with_capacity(cap)
|
||||
}
|
||||
@ -620,7 +620,7 @@ impl MyMemWriter0 {
|
||||
|
||||
impl Writer for MyMemWriter0 {
|
||||
#[inline]
|
||||
fn write(&mut self, buf: &[u8]) -> io::IoResult<()> {
|
||||
fn write_all(&mut self, buf: &[u8]) -> old_io::IoResult<()> {
|
||||
self.buf.push_all(buf);
|
||||
Ok(())
|
||||
}
|
||||
@ -631,7 +631,7 @@ struct MyMemWriter1 {
|
||||
}
|
||||
|
||||
impl MyMemWriter1 {
|
||||
pub fn with_capacity(cap: uint) -> MyMemWriter1 {
|
||||
pub fn with_capacity(cap: usize) -> MyMemWriter1 {
|
||||
MyMemWriter1 {
|
||||
buf: Vec::with_capacity(cap)
|
||||
}
|
||||
@ -652,7 +652,7 @@ fn push_all_bytes(dst: &mut Vec<u8>, src: &[u8]) {
|
||||
dst.set_len(dst_len + src_len);
|
||||
|
||||
::std::ptr::copy_nonoverlapping_memory(
|
||||
dst.as_mut_ptr().offset(dst_len as int),
|
||||
dst.as_mut_ptr().offset(dst_len as isize),
|
||||
src.as_ptr(),
|
||||
src_len);
|
||||
}
|
||||
@ -660,7 +660,7 @@ fn push_all_bytes(dst: &mut Vec<u8>, src: &[u8]) {
|
||||
|
||||
impl Writer for MyMemWriter1 {
|
||||
#[inline]
|
||||
fn write(&mut self, buf: &[u8]) -> io::IoResult<()> {
|
||||
fn write_all(&mut self, buf: &[u8]) -> old_io::IoResult<()> {
|
||||
push_all_bytes(&mut self.buf, buf);
|
||||
Ok(())
|
||||
}
|
||||
@ -674,21 +674,21 @@ fn test_encoder() {
|
||||
|
||||
let log = Log::new();
|
||||
|
||||
let mut wr = Vec::with_capacity(1024);
|
||||
let mut wr = String::with_capacity(1024);
|
||||
|
||||
{
|
||||
let mut encoder = rustc_serialize::json::Encoder::new(&mut wr);
|
||||
log.encode(&mut encoder).unwrap();
|
||||
}
|
||||
|
||||
assert_eq!(wr.as_slice(), JSON_STR.as_bytes());
|
||||
assert_eq!(&wr[], JSON_STR);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_encoder(b: &mut Bencher) {
|
||||
let log = Log::new();
|
||||
|
||||
let mut wr = Vec::with_capacity(1024);
|
||||
let mut wr = String::with_capacity(1024);
|
||||
|
||||
{
|
||||
let mut encoder = rustc_serialize::json::Encoder::new(&mut wr);
|
||||
@ -731,7 +731,7 @@ fn test_serializer_vec() {
|
||||
log.serialize(&mut serializer).unwrap();
|
||||
|
||||
let json = serializer.unwrap();
|
||||
assert_eq!(json.as_slice(), JSON_STR.as_bytes());
|
||||
assert_eq!(&json[], JSON_STR.as_bytes());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -761,7 +761,7 @@ fn bench_serializer_slice(b: &mut Bencher) {
|
||||
|
||||
b.iter(|| {
|
||||
for item in buf.iter_mut(){ *item = 0; }
|
||||
let mut wr = std::io::BufWriter::new(&mut buf);
|
||||
let mut wr = std::old_io::BufWriter::new(&mut buf);
|
||||
|
||||
let mut serializer = json::Serializer::new(wr.by_ref());
|
||||
log.serialize(&mut serializer).unwrap();
|
||||
@ -780,7 +780,7 @@ fn test_serializer_my_mem_writer0() {
|
||||
log.serialize(&mut serializer).unwrap();
|
||||
}
|
||||
|
||||
assert_eq!(wr.buf.as_slice(), JSON_STR.as_bytes());
|
||||
assert_eq!(&wr.buf[], JSON_STR.as_bytes());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -811,7 +811,7 @@ fn test_serializer_my_mem_writer1() {
|
||||
log.serialize(&mut serializer).unwrap();
|
||||
}
|
||||
|
||||
assert_eq!(wr.buf.as_slice(), JSON_STR.as_bytes());
|
||||
assert_eq!(&wr.buf[], JSON_STR.as_bytes());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -847,10 +847,10 @@ fn manual_serialize_no_escape<W: Writer>(wr: &mut W, log: &Log) {
|
||||
wr.write_str(",\"zone_id\":").unwrap();
|
||||
(write!(wr, "{}", log.zone_id)).unwrap();
|
||||
wr.write_str(",\"zone_plan\":").unwrap();
|
||||
(write!(wr, "{}", log.zone_plan as uint)).unwrap();
|
||||
(write!(wr, "{}", log.zone_plan as usize)).unwrap();
|
||||
|
||||
wr.write_str(",\"http\":{\"protocol\":").unwrap();
|
||||
(write!(wr, "{}", log.http.protocol as uint)).unwrap();
|
||||
(write!(wr, "{}", log.http.protocol as usize)).unwrap();
|
||||
wr.write_str(",\"status\":").unwrap();
|
||||
(write!(wr, "{}", log.http.status)).unwrap();
|
||||
wr.write_str(",\"host_status\":").unwrap();
|
||||
@ -858,7 +858,7 @@ fn manual_serialize_no_escape<W: Writer>(wr: &mut W, log: &Log) {
|
||||
wr.write_str(",\"up_status\":").unwrap();
|
||||
(write!(wr, "{}", log.http.up_status)).unwrap();
|
||||
wr.write_str(",\"method\":").unwrap();
|
||||
(write!(wr, "{}", log.http.method as uint)).unwrap();
|
||||
(write!(wr, "{}", log.http.method as usize)).unwrap();
|
||||
wr.write_str(",\"content_type\":").unwrap();
|
||||
(write!(wr, "\"{}\"", log.http.content_type)).unwrap();
|
||||
wr.write_str(",\"user_agent\":").unwrap();
|
||||
@ -878,12 +878,12 @@ fn manual_serialize_no_escape<W: Writer>(wr: &mut W, log: &Log) {
|
||||
(write!(wr, "\"{}\"", log.origin.hostname)).unwrap();
|
||||
|
||||
wr.write_str(",\"protocol\":").unwrap();
|
||||
(write!(wr, "{}", log.origin.protocol as uint)).unwrap();
|
||||
(write!(wr, "{}", log.origin.protocol as usize)).unwrap();
|
||||
|
||||
wr.write_str("},\"country\":").unwrap();
|
||||
(write!(wr, "{}", log.country as uint)).unwrap();
|
||||
(write!(wr, "{}", log.country as usize)).unwrap();
|
||||
wr.write_str(",\"cache_status\":").unwrap();
|
||||
(write!(wr, "{}", log.cache_status as uint)).unwrap();
|
||||
(write!(wr, "{}", log.cache_status as usize)).unwrap();
|
||||
wr.write_str(",\"server_ip\":").unwrap();
|
||||
(write!(wr, "\"{}\"", log.server_ip)).unwrap();
|
||||
wr.write_str(",\"server_name\":").unwrap();
|
||||
@ -910,14 +910,14 @@ fn manual_serialize_escape<W: Writer>(wr: &mut W, log: &Log) {
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "zone_plan").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
(write!(wr, "{}", log.zone_plan as int)).unwrap();
|
||||
(write!(wr, "{}", log.zone_plan as isize)).unwrap();
|
||||
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "http").unwrap();
|
||||
wr.write_str(":{").unwrap();
|
||||
escape_str(wr, "protocol").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
(write!(wr, "{}", log.http.protocol as uint)).unwrap();
|
||||
(write!(wr, "{}", log.http.protocol as usize)).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "status").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
@ -933,23 +933,23 @@ fn manual_serialize_escape<W: Writer>(wr: &mut W, log: &Log) {
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "method").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
(write!(wr, "{}", log.http.method as uint)).unwrap();
|
||||
(write!(wr, "{}", log.http.method as usize)).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "content_type").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.http.content_type.as_slice()).unwrap();
|
||||
escape_str(wr, &log.http.content_type).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "user_agent").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.http.user_agent.as_slice()).unwrap();
|
||||
escape_str(wr, &log.http.user_agent).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "referer").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.http.referer.as_slice()).unwrap();
|
||||
escape_str(wr, &log.http.referer).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "request_uri").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.http.request_uri.as_slice()).unwrap();
|
||||
escape_str(wr, &log.http.request_uri).unwrap();
|
||||
|
||||
wr.write_str("},").unwrap();
|
||||
escape_str(wr, "origin").unwrap();
|
||||
@ -957,7 +957,7 @@ fn manual_serialize_escape<W: Writer>(wr: &mut W, log: &Log) {
|
||||
|
||||
escape_str(wr, "ip").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.origin.ip.as_slice()).unwrap();
|
||||
escape_str(wr, &log.origin.ip).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "port").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
@ -965,32 +965,32 @@ fn manual_serialize_escape<W: Writer>(wr: &mut W, log: &Log) {
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "hostname").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.origin.hostname.as_slice()).unwrap();
|
||||
escape_str(wr, &log.origin.hostname).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "protocol").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
(write!(wr, "{}", log.origin.protocol as uint)).unwrap();
|
||||
(write!(wr, "{}", log.origin.protocol as usize)).unwrap();
|
||||
|
||||
wr.write_str("},").unwrap();
|
||||
escape_str(wr, "country").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
(write!(wr, "{}", log.country as uint)).unwrap();
|
||||
(write!(wr, "{}", log.country as usize)).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "cache_status").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
(write!(wr, "{}", log.cache_status as uint)).unwrap();
|
||||
(write!(wr, "{}", log.cache_status as usize)).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "server_ip").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.server_ip.as_slice()).unwrap();
|
||||
escape_str(wr, &log.server_ip).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "server_name").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.server_name.as_slice()).unwrap();
|
||||
escape_str(wr, &log.server_name).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "remote_ip").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.remote_ip.as_slice()).unwrap();
|
||||
escape_str(wr, &log.remote_ip).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "bytes_dlv").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
@ -999,7 +999,7 @@ fn manual_serialize_escape<W: Writer>(wr: &mut W, log: &Log) {
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "ray_id").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.ray_id.as_slice()).unwrap();
|
||||
escape_str(wr, &log.ray_id).unwrap();
|
||||
wr.write_str("}").unwrap();
|
||||
}
|
||||
|
||||
@ -1011,7 +1011,7 @@ fn test_manual_serialize_vec_no_escape() {
|
||||
manual_serialize_no_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1036,7 +1036,7 @@ fn test_manual_serialize_vec_escape() {
|
||||
manual_serialize_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1062,7 +1062,7 @@ fn test_manual_serialize_my_mem_writer0_no_escape() {
|
||||
manual_serialize_no_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1088,7 +1088,7 @@ fn test_manual_serialize_my_mem_writer0_escape() {
|
||||
manual_serialize_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1114,7 +1114,7 @@ fn test_manual_serialize_my_mem_writer1_no_escape() {
|
||||
manual_serialize_no_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1140,7 +1140,7 @@ fn test_manual_serialize_my_mem_writer1_escape() {
|
||||
manual_serialize_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1167,16 +1167,16 @@ fn direct<W: Writer>(wr: &mut W, log: &Log) {
|
||||
|
||||
serializer.serialize_struct_elt("timestamp", &log.timestamp).unwrap();
|
||||
serializer.serialize_struct_elt("zone_id", &log.zone_id).unwrap();
|
||||
serializer.serialize_struct_elt("zone_plan", &(log.zone_plan as uint)).unwrap();
|
||||
serializer.serialize_struct_elt("zone_plan", &(log.zone_plan as usize)).unwrap();
|
||||
serializer.serialize_struct_elt("http", &log.http).unwrap();
|
||||
serializer.serialize_struct_elt("origin", &log.origin).unwrap();
|
||||
serializer.serialize_struct_elt("country", &(log.country as uint)).unwrap();
|
||||
serializer.serialize_struct_elt("cache_status", &(log.cache_status as uint)).unwrap();
|
||||
serializer.serialize_struct_elt("server_ip", &log.server_ip.as_slice()).unwrap();
|
||||
serializer.serialize_struct_elt("server_name", &log.server_name.as_slice()).unwrap();
|
||||
serializer.serialize_struct_elt("remote_ip", &log.remote_ip.as_slice()).unwrap();
|
||||
serializer.serialize_struct_elt("country", &(log.country as usize)).unwrap();
|
||||
serializer.serialize_struct_elt("cache_status", &(log.cache_status as usize)).unwrap();
|
||||
serializer.serialize_struct_elt("server_ip", &log.server_ip).unwrap();
|
||||
serializer.serialize_struct_elt("server_name", &log.server_name).unwrap();
|
||||
serializer.serialize_struct_elt("remote_ip", &log.remote_ip).unwrap();
|
||||
serializer.serialize_struct_elt("bytes_dlv", &log.bytes_dlv).unwrap();
|
||||
serializer.serialize_struct_elt("ray_id", &log.ray_id.as_slice()).unwrap();
|
||||
serializer.serialize_struct_elt("ray_id", &log.ray_id).unwrap();
|
||||
|
||||
serializer.serialize_struct_end().unwrap();
|
||||
}
|
||||
@ -1189,7 +1189,7 @@ fn test_direct_vec() {
|
||||
direct(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1214,7 +1214,7 @@ fn test_direct_my_mem_writer0() {
|
||||
direct(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1240,7 +1240,7 @@ fn test_direct_my_mem_writer1() {
|
||||
direct(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1291,7 +1291,7 @@ fn test_deserializer() {
|
||||
|
||||
#[inline]
|
||||
fn manual_reader_ignore<R: Reader>(rdr: &mut R, buf: &mut [u8], key: &[u8]) {
|
||||
let buf = buf.slice_mut(0, key.len());
|
||||
let buf = &mut buf[0..key.len()];
|
||||
rdr.read(buf).unwrap();
|
||||
assert_eq!(buf, key);
|
||||
}
|
||||
@ -1350,7 +1350,7 @@ fn manual_reader_string<R: Reader>(rdr: &mut R, buf: &mut [u8], key: &[u8]) -> S
|
||||
let b = rdr.read_byte().unwrap();
|
||||
assert!(b == b',' || b == b']' || b == b'}');
|
||||
|
||||
String::from_utf8(buf.slice_to(idx).to_vec()).unwrap()
|
||||
String::from_utf8(buf[..idx].to_vec()).unwrap()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -1432,7 +1432,7 @@ fn manual_reader_deserialize<R: Reader>(rdr: &mut R) -> Log {
|
||||
|
||||
#[inline]
|
||||
fn manual_iter_ignore<R: Iterator<Item=u8>>(mut rdr: R, buf: &mut [u8], key: &[u8]) {
|
||||
let buf = buf.slice_mut(0, key.len());
|
||||
let buf = &mut buf[0..key.len()];
|
||||
|
||||
for idx in range(0, key.len()) {
|
||||
buf[idx] = rdr.next().unwrap();
|
||||
@ -1494,7 +1494,7 @@ fn manual_iter_string<R: Iterator<Item=u8>>(mut rdr: R, buf: &mut [u8], key: &[u
|
||||
let b = rdr.next().unwrap();
|
||||
assert!(b == b',' || b == b']' || b == b'}');
|
||||
|
||||
String::from_utf8(buf.slice_to(idx).to_vec()).unwrap()
|
||||
String::from_utf8(buf[..idx].to_vec()).unwrap()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -1589,7 +1589,7 @@ fn bench_deserializers(b: &mut Bencher) {
|
||||
|
||||
b.bytes = s.len() as u64;
|
||||
|
||||
for _ in range(0i, 10000) {
|
||||
for _ in range(0is, 10000) {
|
||||
let _log: Log = json::from_str(s).unwrap();
|
||||
}
|
||||
}
|
||||
@ -1618,7 +1618,7 @@ fn bench_reader_manual_reader_deserializer(b: &mut Bencher) {
|
||||
fn bench_reader_manual_reader_deserializers(b: &mut Bencher) {
|
||||
b.bytes = JSON_STR.len() as u64;
|
||||
|
||||
for _ in range(0i, 100000) {
|
||||
for _ in range(0is, 100000) {
|
||||
let mut rdr = JSON_STR.as_bytes();
|
||||
let _ = manual_reader_deserialize(&mut rdr);
|
||||
}
|
||||
@ -1646,7 +1646,7 @@ fn bench_iter_manual_iter_deserializer(b: &mut Bencher) {
|
||||
fn bench_iter_manual_iter_deserializers(b: &mut Bencher) {
|
||||
b.bytes = JSON_STR.len() as u64;
|
||||
|
||||
for _ in range(0i, 10000) {
|
||||
for _ in range(0is, 10000) {
|
||||
let _ = manual_iter_deserialize(JSON_STR.bytes());
|
||||
}
|
||||
}
|
||||
@ -1681,7 +1681,7 @@ fn bench_iter_manual_reader_as_iter_deserializer(b: &mut Bencher) {
|
||||
fn bench_iter_manual_reader_as_iter_deserializers(b: &mut Bencher) {
|
||||
b.bytes = JSON_STR.len() as u64;
|
||||
|
||||
for _ in range(0i, 10000) {
|
||||
for _ in range(0is, 10000) {
|
||||
let mut rdr = JSON_STR.as_bytes();
|
||||
let iter = Bytes::new(&mut rdr)
|
||||
.map(|x| x.unwrap());
|
||||
|
@ -7,7 +7,7 @@ extern crate serde;
|
||||
extern crate "rustc-serialize" as rustc_serialize;
|
||||
extern crate test;
|
||||
|
||||
use std::fmt::Show;
|
||||
use std::fmt::Debug;
|
||||
use std::collections::HashMap;
|
||||
use test::Bencher;
|
||||
|
||||
@ -17,7 +17,7 @@ use serde::de::{Deserializer, Deserialize};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(PartialEq, Show)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum Error {
|
||||
EndOfStream,
|
||||
SyntaxError,
|
||||
@ -33,23 +33,23 @@ mod decoder {
|
||||
|
||||
use super::Error;
|
||||
use super::Error::{EndOfStream, SyntaxError, OtherError};
|
||||
use self::Value::{StringValue, IntValue};
|
||||
use self::Value::{StringValue, IsizeValue};
|
||||
|
||||
enum Value {
|
||||
StringValue(String),
|
||||
IntValue(int),
|
||||
IsizeValue(isize),
|
||||
}
|
||||
|
||||
pub struct IntDecoder {
|
||||
len: uint,
|
||||
iter: IntoIter<String, int>,
|
||||
pub struct IsizeDecoder {
|
||||
len: usize,
|
||||
iter: IntoIter<String, isize>,
|
||||
stack: Vec<Value>,
|
||||
}
|
||||
|
||||
impl IntDecoder {
|
||||
impl IsizeDecoder {
|
||||
#[inline]
|
||||
pub fn new(values: HashMap<String, int>) -> IntDecoder {
|
||||
IntDecoder {
|
||||
pub fn new(values: HashMap<String, isize>) -> IsizeDecoder {
|
||||
IsizeDecoder {
|
||||
len: values.len(),
|
||||
iter: values.into_iter(),
|
||||
stack: vec!(),
|
||||
@ -57,7 +57,7 @@ mod decoder {
|
||||
}
|
||||
}
|
||||
|
||||
impl rustc_serialize::Decoder for IntDecoder {
|
||||
impl rustc_serialize::Decoder for IsizeDecoder {
|
||||
type Error = Error;
|
||||
|
||||
fn error(&mut self, msg: &str) -> Error {
|
||||
@ -66,15 +66,15 @@ mod decoder {
|
||||
|
||||
// Primitive types:
|
||||
fn read_nil(&mut self) -> Result<(), Error> { Err(SyntaxError) }
|
||||
fn read_usize(&mut self) -> Result<uint, Error> { Err(SyntaxError) }
|
||||
fn read_usize(&mut self) -> Result<usize, Error> { Err(SyntaxError) }
|
||||
fn read_u64(&mut self) -> Result<u64, Error> { Err(SyntaxError) }
|
||||
fn read_u32(&mut self) -> Result<u32, Error> { Err(SyntaxError) }
|
||||
fn read_u16(&mut self) -> Result<u16, Error> { Err(SyntaxError) }
|
||||
fn read_u8(&mut self) -> Result<u8, Error> { Err(SyntaxError) }
|
||||
#[inline]
|
||||
fn read_isize(&mut self) -> Result<int, Error> {
|
||||
fn read_isize(&mut self) -> Result<isize, Error> {
|
||||
match self.stack.pop() {
|
||||
Some(IntValue(x)) => Ok(x),
|
||||
Some(IsizeValue(x)) => Ok(x),
|
||||
Some(_) => Err(SyntaxError),
|
||||
None => Err(EndOfStream),
|
||||
}
|
||||
@ -98,104 +98,104 @@ mod decoder {
|
||||
|
||||
// Compound types:
|
||||
fn read_enum<T, F>(&mut self, _name: &str, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_enum_variant<T, F>(&mut self, _names: &[&str], _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut IsizeDecoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_enum_variant_arg<T, F>(&mut self, _a_idx: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_enum_variant_arg<T, F>(&mut self, _a_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_enum_struct_variant<T, F>(&mut self, _names: &[&str], _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut IsizeDecoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_enum_struct_variant_field<T, F>(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_enum_struct_variant_field<T, F>(&mut self, _f_name: &str, _f_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_struct<T, F>(&mut self, _s_name: &str, _len: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_struct<T, F>(&mut self, _s_name: &str, _len: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_struct_field<T, F>(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_struct_field<T, F>(&mut self, _f_name: &str, _f_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_tuple<T, F>(&mut self, _len: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_tuple<T, F>(&mut self, _len: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_tuple_arg<T, F>(&mut self, _a_idx: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_tuple_arg<T, F>(&mut self, _a_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_tuple_struct<T, F>(&mut self, _s_name: &str, _len: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_tuple_struct<T, F>(&mut self, _s_name: &str, _len: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_tuple_struct_arg<T, F>(&mut self, _a_idx: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_tuple_struct_arg<T, F>(&mut self, _a_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
// Specialized types:
|
||||
fn read_option<T, F>(&mut self, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder, bool) -> Result<T, Error>,
|
||||
F: FnOnce(&mut IsizeDecoder, bool) -> Result<T, Error>,
|
||||
{
|
||||
Err(SyntaxError)
|
||||
}
|
||||
|
||||
fn read_seq<T, F>(&mut self, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut IsizeDecoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
Err(SyntaxError)
|
||||
}
|
||||
|
||||
fn read_seq_elt<T, F>(&mut self, _idx: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_seq_elt<T, F>(&mut self, _idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(SyntaxError)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn read_map<T, F>(&mut self, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut IsizeDecoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
let len = self.len;
|
||||
f(self, len)
|
||||
}
|
||||
#[inline]
|
||||
fn read_map_elt_key<T, F>(&mut self, _idx: uint, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_map_elt_key<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
match self.iter.next() {
|
||||
Some((key, value)) => {
|
||||
self.stack.push(IntValue(value));
|
||||
self.stack.push(IsizeValue(value));
|
||||
self.stack.push(StringValue(key));
|
||||
f(self)
|
||||
}
|
||||
@ -206,8 +206,8 @@ mod decoder {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn read_map_elt_val<T, F>(&mut self, _idx: uint, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_map_elt_val<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
f(self)
|
||||
}
|
||||
@ -226,24 +226,24 @@ mod deserializer {
|
||||
|
||||
use serde::de;
|
||||
|
||||
#[derive(PartialEq, Show)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
enum State {
|
||||
StartState,
|
||||
KeyOrEndState,
|
||||
ValueState(int),
|
||||
ValueState(isize),
|
||||
EndState,
|
||||
}
|
||||
|
||||
pub struct IntDeserializer {
|
||||
pub struct IsizeDeserializer {
|
||||
stack: Vec<State>,
|
||||
len: uint,
|
||||
iter: IntoIter<String, int>,
|
||||
len: usize,
|
||||
iter: IntoIter<String, isize>,
|
||||
}
|
||||
|
||||
impl IntDeserializer {
|
||||
impl IsizeDeserializer {
|
||||
#[inline]
|
||||
pub fn new(values: HashMap<String, int>) -> IntDeserializer {
|
||||
IntDeserializer {
|
||||
pub fn new(values: HashMap<String, isize>) -> IsizeDeserializer {
|
||||
IsizeDeserializer {
|
||||
stack: vec!(StartState),
|
||||
len: values.len(),
|
||||
iter: values.into_iter(),
|
||||
@ -251,7 +251,7 @@ mod deserializer {
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for IntDeserializer {
|
||||
impl Iterator for IsizeDeserializer {
|
||||
type Item = Result<de::Token, Error>;
|
||||
|
||||
#[inline]
|
||||
@ -275,7 +275,7 @@ mod deserializer {
|
||||
}
|
||||
Some(ValueState(x)) => {
|
||||
self.stack.push(KeyOrEndState);
|
||||
Some(Ok(de::Token::Int(x)))
|
||||
Some(Ok(de::Token::Isize(x)))
|
||||
}
|
||||
Some(EndState) => {
|
||||
None
|
||||
@ -287,7 +287,7 @@ mod deserializer {
|
||||
}
|
||||
}
|
||||
|
||||
impl de::Deserializer<Error> for IntDeserializer {
|
||||
impl de::Deserializer<Error> for IsizeDeserializer {
|
||||
#[inline]
|
||||
fn end_of_stream_error(&mut self) -> Error {
|
||||
EndOfStream
|
||||
@ -310,7 +310,7 @@ mod deserializer {
|
||||
|
||||
#[inline]
|
||||
fn missing_field<
|
||||
T: de::Deserialize<IntDeserializer, Error>
|
||||
T: de::Deserialize<IsizeDeserializer, Error>
|
||||
>(&mut self, _field: &'static str) -> Result<T, Error> {
|
||||
Err(SyntaxError)
|
||||
}
|
||||
@ -321,7 +321,7 @@ mod deserializer {
|
||||
|
||||
fn run_decoder<
|
||||
D: Decoder<Error=Error>,
|
||||
T: Clone + PartialEq + Show + Decodable
|
||||
T: Clone + PartialEq + Debug + Decodable
|
||||
>(mut d: D, value: T) {
|
||||
let v = Decodable::decode(&mut d);
|
||||
|
||||
@ -331,37 +331,37 @@ fn run_decoder<
|
||||
#[bench]
|
||||
fn bench_decoder_000(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let m: HashMap<String, int> = HashMap::new();
|
||||
run_decoder(decoder::IntDecoder::new(m.clone()), m)
|
||||
let m: HashMap<String, isize> = HashMap::new();
|
||||
run_decoder(decoder::IsizeDecoder::new(m.clone()), m)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_decoder_003(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let mut m: HashMap<String, int> = HashMap::new();
|
||||
for i in range(0i, 3) {
|
||||
let mut m: HashMap<String, isize> = HashMap::new();
|
||||
for i in range(0is, 3) {
|
||||
m.insert(i.to_string(), i);
|
||||
}
|
||||
run_decoder(decoder::IntDecoder::new(m.clone()), m)
|
||||
run_decoder(decoder::IsizeDecoder::new(m.clone()), m)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_decoder_100(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let mut m: HashMap<String, int> = HashMap::new();
|
||||
for i in range(0i, 100) {
|
||||
let mut m: HashMap<String, isize> = HashMap::new();
|
||||
for i in range(0is, 100) {
|
||||
m.insert(i.to_string(), i);
|
||||
}
|
||||
run_decoder(decoder::IntDecoder::new(m.clone()), m)
|
||||
run_decoder(decoder::IsizeDecoder::new(m.clone()), m)
|
||||
})
|
||||
}
|
||||
|
||||
fn run_deserializer<
|
||||
D: Deserializer<E>,
|
||||
E: Show,
|
||||
T: Clone + PartialEq + Show + Deserialize<D, E>
|
||||
E: Debug,
|
||||
T: Clone + PartialEq + Debug + Deserialize<D, E>
|
||||
>(mut d: D, value: T) {
|
||||
let v: T = Deserialize::deserialize(&mut d).unwrap();
|
||||
|
||||
@ -371,29 +371,29 @@ fn run_deserializer<
|
||||
#[bench]
|
||||
fn bench_deserializer_000(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let m: HashMap<String, int> = HashMap::new();
|
||||
run_deserializer(deserializer::IntDeserializer::new(m.clone()), m)
|
||||
let m: HashMap<String, isize> = HashMap::new();
|
||||
run_deserializer(deserializer::IsizeDeserializer::new(m.clone()), m)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_deserializer_003(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let mut m: HashMap<String, int> = HashMap::new();
|
||||
for i in range(0i, 3) {
|
||||
let mut m: HashMap<String, isize> = HashMap::new();
|
||||
for i in range(0is, 3) {
|
||||
m.insert(i.to_string(), i);
|
||||
}
|
||||
run_deserializer(deserializer::IntDeserializer::new(m.clone()), m)
|
||||
run_deserializer(deserializer::IsizeDeserializer::new(m.clone()), m)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_deserializer_100(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let mut m: HashMap<String, int> = HashMap::new();
|
||||
for i in range(0i, 100) {
|
||||
let mut m: HashMap<String, isize> = HashMap::new();
|
||||
for i in range(0is, 100) {
|
||||
m.insert(i.to_string(), i);
|
||||
}
|
||||
run_deserializer(deserializer::IntDeserializer::new(m.clone()), m)
|
||||
run_deserializer(deserializer::IsizeDeserializer::new(m.clone()), m)
|
||||
})
|
||||
}
|
||||
|
@ -16,17 +16,17 @@ use serde::de::{Deserializer, Deserialize};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Clone, PartialEq, Show, RustcDecodable)]
|
||||
#[derive(Clone, PartialEq, Debug, RustcDecodable)]
|
||||
#[derive_deserialize]
|
||||
struct Inner {
|
||||
a: (),
|
||||
b: uint,
|
||||
b: usize,
|
||||
c: HashMap<String, Option<char>>,
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Clone, PartialEq, Show, RustcDecodable)]
|
||||
#[derive(Clone, PartialEq, Debug, RustcDecodable)]
|
||||
#[derive_deserialize]
|
||||
struct Outer {
|
||||
inner: Vec<Inner>,
|
||||
@ -34,7 +34,7 @@ struct Outer {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Show)]
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
EndOfStream,
|
||||
SyntaxError(String),
|
||||
@ -54,7 +54,7 @@ mod decoder {
|
||||
OuterState,
|
||||
InnerState,
|
||||
NullState,
|
||||
UintState,
|
||||
UsizeState,
|
||||
CharState,
|
||||
StringState,
|
||||
FieldState,
|
||||
@ -63,12 +63,12 @@ mod decoder {
|
||||
OptionState,
|
||||
};
|
||||
|
||||
#[derive(Show)]
|
||||
#[derive(Debug)]
|
||||
enum State {
|
||||
OuterState(Outer),
|
||||
InnerState(Inner),
|
||||
NullState,
|
||||
UintState(uint),
|
||||
UsizeState(usize),
|
||||
CharState(char),
|
||||
StringState(String),
|
||||
FieldState(&'static str),
|
||||
@ -107,9 +107,9 @@ mod decoder {
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn read_usize(&mut self) -> Result<uint, Error> {
|
||||
fn read_usize(&mut self) -> Result<usize, Error> {
|
||||
match self.stack.pop() {
|
||||
Some(UintState(value)) => Ok(value),
|
||||
Some(UsizeState(value)) => Ok(value),
|
||||
_ => Err(Error::SyntaxError("UintState".to_string())),
|
||||
}
|
||||
}
|
||||
@ -117,7 +117,7 @@ mod decoder {
|
||||
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_isize(&mut self) -> Result<int, Error> { Err(Error::SyntaxError("".to_string())) }
|
||||
fn read_isize(&mut self) -> Result<isize, 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())) }
|
||||
@ -148,31 +148,31 @@ mod decoder {
|
||||
}
|
||||
|
||||
fn read_enum_variant<T, F>(&mut self, _names: &[&str], _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut OuterDecoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut OuterDecoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError("".to_string()))
|
||||
}
|
||||
|
||||
fn read_enum_variant_arg<T, F>(&mut self, _a_idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_enum_variant_arg<T, F>(&mut self, _a_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut OuterDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError("".to_string()))
|
||||
}
|
||||
|
||||
fn read_enum_struct_variant<T, F>(&mut self, _names: &[&str], _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut OuterDecoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut OuterDecoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError("".to_string()))
|
||||
}
|
||||
|
||||
fn read_enum_struct_variant_field<T, F>(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_enum_struct_variant_field<T, F>(&mut self, _f_name: &str, _f_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut OuterDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError("".to_string()))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn read_struct<T, F>(&mut self, s_name: &str, _len: uint, f: F) -> Result<T, Error> where
|
||||
fn read_struct<T, F>(&mut self, s_name: &str, _len: usize, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut OuterDecoder) -> Result<T, Error>,
|
||||
{
|
||||
match self.stack.pop() {
|
||||
@ -190,7 +190,7 @@ mod decoder {
|
||||
self.stack.push(MapState(c));
|
||||
self.stack.push(FieldState("c"));
|
||||
|
||||
self.stack.push(UintState(b));
|
||||
self.stack.push(UsizeState(b));
|
||||
self.stack.push(FieldState("b"));
|
||||
|
||||
self.stack.push(NullState);
|
||||
@ -204,7 +204,7 @@ mod decoder {
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn read_struct_field<T, F>(&mut self, f_name: &str, _f_idx: uint, f: F) -> Result<T, Error> where
|
||||
fn read_struct_field<T, F>(&mut self, f_name: &str, _f_idx: usize, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut OuterDecoder) -> Result<T, Error>,
|
||||
{
|
||||
match self.stack.pop() {
|
||||
@ -219,25 +219,25 @@ mod decoder {
|
||||
}
|
||||
}
|
||||
|
||||
fn read_tuple<T, F>(&mut self, _len: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_tuple<T, F>(&mut self, _len: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut OuterDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError("".to_string()))
|
||||
}
|
||||
|
||||
fn read_tuple_arg<T, F>(&mut self, _a_idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_tuple_arg<T, F>(&mut self, _a_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut OuterDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError("".to_string()))
|
||||
}
|
||||
|
||||
fn read_tuple_struct<T, F>(&mut self, _s_name: &str, _len: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_tuple_struct<T, F>(&mut self, _s_name: &str, _len: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut OuterDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError("".to_string()))
|
||||
}
|
||||
|
||||
fn read_tuple_struct_arg<T, F>(&mut self, _a_idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_tuple_struct_arg<T, F>(&mut self, _a_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut OuterDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError("".to_string()))
|
||||
@ -256,7 +256,7 @@ mod decoder {
|
||||
|
||||
#[inline]
|
||||
fn read_seq<T, F>(&mut self, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut OuterDecoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut OuterDecoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
match self.stack.pop() {
|
||||
Some(VecState(value)) => {
|
||||
@ -270,7 +270,7 @@ mod decoder {
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn read_seq_elt<T, F>(&mut self, _idx: uint, f: F) -> Result<T, Error> where
|
||||
fn read_seq_elt<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut OuterDecoder) -> Result<T, Error>,
|
||||
{
|
||||
f(self)
|
||||
@ -278,12 +278,12 @@ mod decoder {
|
||||
|
||||
#[inline]
|
||||
fn read_map<T, F>(&mut self, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut OuterDecoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut OuterDecoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
match self.stack.pop() {
|
||||
Some(MapState(map)) => {
|
||||
let len = map.len();
|
||||
for (key, value) in map.into_iter() {
|
||||
for (key, value) in map {
|
||||
match value {
|
||||
Some(c) => {
|
||||
self.stack.push(CharState(c));
|
||||
@ -301,14 +301,14 @@ mod decoder {
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn read_map_elt_key<T, F>(&mut self, _idx: uint, f: F) -> Result<T, Error> where
|
||||
fn read_map_elt_key<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut OuterDecoder) -> Result<T, Error>,
|
||||
{
|
||||
f(self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn read_map_elt_val<T, F>(&mut self, _idx: uint, f: F) -> Result<T, Error> where
|
||||
fn read_map_elt_val<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut OuterDecoder) -> Result<T, Error>,
|
||||
{
|
||||
f(self)
|
||||
@ -329,23 +329,23 @@ mod deserializer {
|
||||
InnerState,
|
||||
FieldState,
|
||||
NullState,
|
||||
UintState,
|
||||
UsizeState,
|
||||
CharState,
|
||||
StringState,
|
||||
OptionState,
|
||||
//TupleState(uint),
|
||||
//TupleState(usize),
|
||||
VecState,
|
||||
MapState,
|
||||
EndState,
|
||||
};
|
||||
|
||||
#[derive(Show)]
|
||||
#[derive(Debug)]
|
||||
enum State {
|
||||
OuterState(Outer),
|
||||
InnerState(Inner),
|
||||
FieldState(&'static str),
|
||||
NullState,
|
||||
UintState(uint),
|
||||
UsizeState(usize),
|
||||
CharState(char),
|
||||
StringState(String),
|
||||
OptionState(bool),
|
||||
@ -385,7 +385,7 @@ mod deserializer {
|
||||
self.stack.push(MapState(c));
|
||||
self.stack.push(FieldState("c"));
|
||||
|
||||
self.stack.push(UintState(b));
|
||||
self.stack.push(UsizeState(b));
|
||||
self.stack.push(FieldState("b"));
|
||||
|
||||
self.stack.push(NullState);
|
||||
@ -404,7 +404,7 @@ mod deserializer {
|
||||
Some(MapState(value)) => {
|
||||
self.stack.push(EndState);
|
||||
let len = value.len();
|
||||
for (key, value) in value.into_iter() {
|
||||
for (key, value) in value {
|
||||
match value {
|
||||
Some(c) => {
|
||||
self.stack.push(CharState(c));
|
||||
@ -420,7 +420,7 @@ mod deserializer {
|
||||
}
|
||||
//Some(TupleState(len)) => Some(Ok(de::Token::TupleStart(len))),
|
||||
Some(NullState) => Some(Ok(de::Token::Null)),
|
||||
Some(UintState(x)) => Some(Ok(de::Token::Uint(x))),
|
||||
Some(UsizeState(x)) => Some(Ok(de::Token::Usize(x))),
|
||||
Some(CharState(x)) => Some(Ok(de::Token::Char(x))),
|
||||
Some(StringState(x)) => Some(Ok(de::Token::String(x))),
|
||||
Some(OptionState(x)) => Some(Ok(de::Token::Option(x))),
|
||||
|
@ -7,7 +7,7 @@ extern crate serde;
|
||||
extern crate "rustc-serialize" as rustc_serialize;
|
||||
extern crate test;
|
||||
|
||||
use std::fmt::Show;
|
||||
use std::fmt::Debug;
|
||||
use test::Bencher;
|
||||
|
||||
use rustc_serialize::{Decoder, Decodable};
|
||||
@ -16,7 +16,7 @@ use serde::de::{Deserializer, Deserialize};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(PartialEq, Show)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum Error {
|
||||
EndOfStream,
|
||||
SyntaxError,
|
||||
@ -32,22 +32,22 @@ mod decoder {
|
||||
use super::Error;
|
||||
use super::Error::{EndOfStream, SyntaxError, OtherError};
|
||||
|
||||
pub struct IntDecoder {
|
||||
len: uint,
|
||||
iter: vec::IntoIter<int>,
|
||||
pub struct IsizeDecoder {
|
||||
len: usize,
|
||||
iter: vec::IntoIter<isize>,
|
||||
}
|
||||
|
||||
impl IntDecoder {
|
||||
impl IsizeDecoder {
|
||||
#[inline]
|
||||
pub fn new(values: Vec<int>) -> IntDecoder {
|
||||
IntDecoder {
|
||||
pub fn new(values: Vec<isize>) -> IsizeDecoder {
|
||||
IsizeDecoder {
|
||||
len: values.len(),
|
||||
iter: values.into_iter(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl rustc_serialize::Decoder for IntDecoder {
|
||||
impl rustc_serialize::Decoder for IsizeDecoder {
|
||||
type Error = Error;
|
||||
|
||||
fn error(&mut self, msg: &str) -> Error {
|
||||
@ -56,13 +56,13 @@ mod decoder {
|
||||
|
||||
// Primitive types:
|
||||
fn read_nil(&mut self) -> Result<(), Error> { Err(SyntaxError) }
|
||||
fn read_usize(&mut self) -> Result<uint, Error> { Err(SyntaxError) }
|
||||
fn read_usize(&mut self) -> Result<usize, Error> { Err(SyntaxError) }
|
||||
fn read_u64(&mut self) -> Result<u64, Error> { Err(SyntaxError) }
|
||||
fn read_u32(&mut self) -> Result<u32, Error> { Err(SyntaxError) }
|
||||
fn read_u16(&mut self) -> Result<u16, Error> { Err(SyntaxError) }
|
||||
fn read_u8(&mut self) -> Result<u8, Error> { Err(SyntaxError) }
|
||||
#[inline]
|
||||
fn read_isize(&mut self) -> Result<int, Error> {
|
||||
fn read_isize(&mut self) -> Result<isize, Error> {
|
||||
match self.iter.next() {
|
||||
Some(value) => Ok(value),
|
||||
None => Err(EndOfStream),
|
||||
@ -80,106 +80,106 @@ mod decoder {
|
||||
|
||||
// Compound types:
|
||||
fn read_enum<T, F>(&mut self, _name: &str, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_enum_variant<T, F>(&mut self, _names: &[&str], _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut IsizeDecoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_enum_variant_arg<T, F>(&mut self, _a_idx: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_enum_variant_arg<T, F>(&mut self, _a_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_enum_struct_variant<T, F>(&mut self, _names: &[&str], _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut IsizeDecoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_enum_struct_variant_field<T, F>(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_enum_struct_variant_field<T, F>(&mut self, _f_name: &str, _f_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_struct<T, F>(&mut self, _s_name: &str, _len: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_struct<T, F>(&mut self, _s_name: &str, _len: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_struct_field<T, F>(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_struct_field<T, F>(&mut self, _f_name: &str, _f_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_tuple<T, F>(&mut self, _len: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_tuple<T, F>(&mut self, _len: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_tuple_arg<T, F>(&mut self, _a_idx: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_tuple_arg<T, F>(&mut self, _a_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_tuple_struct<T, F>(&mut self, _s_name: &str, _len: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_tuple_struct<T, F>(&mut self, _s_name: &str, _len: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_tuple_struct_arg<T, F>(&mut self, _a_idx: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_tuple_struct_arg<T, F>(&mut self, _a_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
// Specialized types:
|
||||
fn read_option<T, F>(&mut self, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder, bool) -> Result<T, Error>,
|
||||
F: FnOnce(&mut IsizeDecoder, bool) -> Result<T, Error>,
|
||||
{
|
||||
Err(SyntaxError)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn read_seq<T, F>(&mut self, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut IsizeDecoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
let len = self.len;
|
||||
f(self, len)
|
||||
}
|
||||
#[inline]
|
||||
fn read_seq_elt<T, F>(&mut self, _idx: uint, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_seq_elt<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
f(self)
|
||||
}
|
||||
|
||||
fn read_map<T, F>(&mut self, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut IsizeDecoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
Err(SyntaxError)
|
||||
}
|
||||
|
||||
fn read_map_elt_key<T, F>(&mut self, _idx: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_map_elt_key<T, F>(&mut self, _idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(SyntaxError)
|
||||
}
|
||||
|
||||
fn read_map_elt_val<T, F>(&mut self, _idx: uint, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IntDecoder) -> Result<T, Error>,
|
||||
fn read_map_elt_val<T, F>(&mut self, _idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut IsizeDecoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(SyntaxError)
|
||||
}
|
||||
@ -187,7 +187,7 @@ mod decoder {
|
||||
|
||||
|
||||
pub struct U8Decoder {
|
||||
len: uint,
|
||||
len: usize,
|
||||
iter: vec::IntoIter<u8>,
|
||||
}
|
||||
|
||||
@ -210,7 +210,7 @@ mod decoder {
|
||||
|
||||
// Primitive types:
|
||||
fn read_nil(&mut self) -> Result<(), Error> { Err(SyntaxError) }
|
||||
fn read_usize(&mut self) -> Result<uint, Error> { Err(SyntaxError) }
|
||||
fn read_usize(&mut self) -> Result<usize, Error> { Err(SyntaxError) }
|
||||
fn read_u64(&mut self) -> Result<u64, Error> { Err(SyntaxError) }
|
||||
fn read_u32(&mut self) -> Result<u32, Error> { Err(SyntaxError) }
|
||||
fn read_u16(&mut self) -> Result<u16, Error> { Err(SyntaxError) }
|
||||
@ -222,7 +222,7 @@ mod decoder {
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn read_isize(&mut self) -> Result<int, Error> { Err(SyntaxError) }
|
||||
fn read_isize(&mut self) -> Result<isize, Error> { Err(SyntaxError) }
|
||||
fn read_i64(&mut self) -> Result<i64, Error> { Err(SyntaxError) }
|
||||
fn read_i32(&mut self) -> Result<i32, Error> { Err(SyntaxError) }
|
||||
fn read_i16(&mut self) -> Result<i16, Error> { Err(SyntaxError) }
|
||||
@ -241,60 +241,60 @@ mod decoder {
|
||||
}
|
||||
|
||||
fn read_enum_variant<T, F>(&mut self, _names: &[&str], _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut U8Decoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut U8Decoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_enum_variant_arg<T, F>(&mut self, _a_idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_enum_variant_arg<T, F>(&mut self, _a_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut U8Decoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_enum_struct_variant<T, F>(&mut self, _names: &[&str], _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut U8Decoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut U8Decoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_enum_struct_variant_field<T, F>(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_enum_struct_variant_field<T, F>(&mut self, _f_name: &str, _f_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut U8Decoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_struct<T, F>(&mut self, _s_name: &str, _len: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_struct<T, F>(&mut self, _s_name: &str, _len: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut U8Decoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_struct_field<T, F>(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_struct_field<T, F>(&mut self, _f_name: &str, _f_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut U8Decoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_tuple<T, F>(&mut self, _len: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_tuple<T, F>(&mut self, _len: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut U8Decoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_tuple_arg<T, F>(&mut self, _a_idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_tuple_arg<T, F>(&mut self, _a_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut U8Decoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_tuple_struct<T, F>(&mut self, _s_name: &str, _len: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_tuple_struct<T, F>(&mut self, _s_name: &str, _len: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut U8Decoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
}
|
||||
|
||||
fn read_tuple_struct_arg<T, F>(&mut self, _a_idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_tuple_struct_arg<T, F>(&mut self, _a_idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut U8Decoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(Error::SyntaxError)
|
||||
@ -309,31 +309,31 @@ mod decoder {
|
||||
|
||||
#[inline]
|
||||
fn read_seq<T, F>(&mut self, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut U8Decoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut U8Decoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
let len = self.len;
|
||||
f(self, len)
|
||||
}
|
||||
#[inline]
|
||||
fn read_seq_elt<T, F>(&mut self, _idx: uint, f: F) -> Result<T, Error> where
|
||||
fn read_seq_elt<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut U8Decoder) -> Result<T, Error>,
|
||||
{
|
||||
f(self)
|
||||
}
|
||||
|
||||
fn read_map<T, F>(&mut self, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut U8Decoder, uint) -> Result<T, Error>,
|
||||
F: FnOnce(&mut U8Decoder, usize) -> Result<T, Error>,
|
||||
{
|
||||
Err(SyntaxError)
|
||||
}
|
||||
|
||||
fn read_map_elt_key<T, F>(&mut self, _idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_map_elt_key<T, F>(&mut self, _idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut U8Decoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(SyntaxError)
|
||||
}
|
||||
|
||||
fn read_map_elt_val<T, F>(&mut self, _idx: uint, _f: F) -> Result<T, Error> where
|
||||
fn read_map_elt_val<T, F>(&mut self, _idx: usize, _f: F) -> Result<T, Error> where
|
||||
F: FnOnce(&mut U8Decoder) -> Result<T, Error>,
|
||||
{
|
||||
Err(SyntaxError)
|
||||
@ -353,23 +353,23 @@ mod deserializer {
|
||||
|
||||
use serde::de;
|
||||
|
||||
#[derive(PartialEq, Show)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
enum State {
|
||||
StartState,
|
||||
SepOrEndState,
|
||||
EndState,
|
||||
}
|
||||
|
||||
pub struct IntDeserializer {
|
||||
pub struct IsizeDeserializer {
|
||||
state: State,
|
||||
len: uint,
|
||||
iter: vec::IntoIter<int>,
|
||||
len: usize,
|
||||
iter: vec::IntoIter<isize>,
|
||||
}
|
||||
|
||||
impl IntDeserializer {
|
||||
impl IsizeDeserializer {
|
||||
#[inline]
|
||||
pub fn new(values: Vec<int>) -> IntDeserializer {
|
||||
IntDeserializer {
|
||||
pub fn new(values: Vec<isize>) -> IsizeDeserializer {
|
||||
IsizeDeserializer {
|
||||
state: StartState,
|
||||
len: values.len(),
|
||||
iter: values.into_iter(),
|
||||
@ -377,7 +377,7 @@ mod deserializer {
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for IntDeserializer {
|
||||
impl Iterator for IsizeDeserializer {
|
||||
type Item = Result<de::Token, Error>;
|
||||
|
||||
#[inline]
|
||||
@ -390,7 +390,7 @@ mod deserializer {
|
||||
SepOrEndState => {
|
||||
match self.iter.next() {
|
||||
Some(value) => {
|
||||
Some(Ok(de::Token::Int(value)))
|
||||
Some(Ok(de::Token::Isize(value)))
|
||||
}
|
||||
None => {
|
||||
self.state = EndState;
|
||||
@ -405,7 +405,7 @@ mod deserializer {
|
||||
}
|
||||
}
|
||||
|
||||
impl de::Deserializer<Error> for IntDeserializer {
|
||||
impl de::Deserializer<Error> for IsizeDeserializer {
|
||||
#[inline]
|
||||
fn end_of_stream_error(&mut self) -> Error {
|
||||
EndOfStream
|
||||
@ -428,7 +428,7 @@ mod deserializer {
|
||||
|
||||
#[inline]
|
||||
fn missing_field<
|
||||
T: de::Deserialize<IntDeserializer, Error>
|
||||
T: de::Deserialize<IsizeDeserializer, Error>
|
||||
>(&mut self, _field: &'static str) -> Result<T, Error> {
|
||||
Err(SyntaxError)
|
||||
}
|
||||
@ -436,7 +436,7 @@ mod deserializer {
|
||||
|
||||
pub struct U8Deserializer {
|
||||
state: State,
|
||||
len: uint,
|
||||
len: usize,
|
||||
iter: vec::IntoIter<u8>,
|
||||
}
|
||||
|
||||
@ -513,7 +513,7 @@ mod deserializer {
|
||||
|
||||
fn run_decoder<
|
||||
D: Decoder<Error=Error>,
|
||||
T: Clone + PartialEq + Show + Decodable
|
||||
T: Clone + PartialEq + Debug + Decodable
|
||||
>(mut d: D, value: T) {
|
||||
let v = Decodable::decode(&mut d);
|
||||
|
||||
@ -522,8 +522,8 @@ fn run_decoder<
|
||||
|
||||
fn run_deserializer<
|
||||
D: Deserializer<E>,
|
||||
E: Show,
|
||||
T: Clone + PartialEq + Show + Deserialize<D, E>
|
||||
E: Debug,
|
||||
T: Clone + PartialEq + Debug + Deserialize<D, E>
|
||||
>(mut d: D, value: T) {
|
||||
let v: T = Deserialize::deserialize(&mut d).unwrap();
|
||||
|
||||
@ -533,24 +533,24 @@ fn run_deserializer<
|
||||
#[bench]
|
||||
fn bench_decoder_int_000(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let v: Vec<int> = vec!();
|
||||
run_decoder(decoder::IntDecoder::new(v.clone()), v)
|
||||
let v: Vec<isize> = vec!();
|
||||
run_decoder(decoder::IsizeDecoder::new(v.clone()), v)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_decoder_int_003(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let v: Vec<int> = vec!(1, 2, 3);
|
||||
run_decoder(decoder::IntDecoder::new(v.clone()), v)
|
||||
let v: Vec<isize> = vec!(1, 2, 3);
|
||||
run_decoder(decoder::IsizeDecoder::new(v.clone()), v)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_decoder_int_100(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let v: Vec<int> = range(0i, 100).collect();
|
||||
run_decoder(decoder::IntDecoder::new(v.clone()), v)
|
||||
let v: Vec<isize> = range(0is, 100).collect();
|
||||
run_decoder(decoder::IsizeDecoder::new(v.clone()), v)
|
||||
})
|
||||
}
|
||||
|
||||
@ -581,24 +581,24 @@ fn bench_decoder_u8_100(b: &mut Bencher) {
|
||||
#[bench]
|
||||
fn bench_deserializer_int_000(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let v: Vec<int> = vec!();
|
||||
run_deserializer(deserializer::IntDeserializer::new(v.clone()), v)
|
||||
let v: Vec<isize> = vec!();
|
||||
run_deserializer(deserializer::IsizeDeserializer::new(v.clone()), v)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_deserializer_int_003(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let v: Vec<int> = vec!(1, 2, 3);
|
||||
run_deserializer(deserializer::IntDeserializer::new(v.clone()), v)
|
||||
let v: Vec<isize> = vec!(1, 2, 3);
|
||||
run_deserializer(deserializer::IsizeDeserializer::new(v.clone()), v)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_deserializer_int_100(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let v: Vec<int> = range(0i, 100).collect();
|
||||
run_deserializer(deserializer::IntDeserializer::new(v.clone()), v)
|
||||
let v: Vec<isize> = range(0is, 100).collect();
|
||||
run_deserializer(deserializer::IsizeDeserializer::new(v.clone()), v)
|
||||
})
|
||||
}
|
||||
|
||||
|
17
serde2/Cargo.lock
generated
17
serde2/Cargo.lock
generated
@ -1,17 +0,0 @@
|
||||
[root]
|
||||
name = "serde2"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rustc-serialize 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde2_macros 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-serialize"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "serde2_macros"
|
||||
version = "0.1.0"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![feature(plugin)]
|
||||
#![feature(plugin, io)]
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
#[plugin]
|
||||
@ -8,8 +8,8 @@ extern crate serde2;
|
||||
extern crate "rustc-serialize" as rustc_serialize;
|
||||
extern crate test;
|
||||
|
||||
use std::io;
|
||||
use std::io::ByRefWriter;
|
||||
use std::old_io;
|
||||
use std::old_io::ByRefWriter;
|
||||
use std::num::FromPrimitive;
|
||||
use test::Bencher;
|
||||
|
||||
@ -66,7 +66,7 @@ impl de::Deserialize for HttpField {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Show, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
#[derive(Debug, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
#[derive_serialize]
|
||||
//#[derive_deserialize]
|
||||
struct Http {
|
||||
@ -135,7 +135,7 @@ impl de::Deserialize for Http {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Show, PartialEq, FromPrimitive)]
|
||||
#[derive(Copy, Debug, PartialEq, FromPrimitive)]
|
||||
enum HttpProtocol {
|
||||
HTTP_PROTOCOL_UNKNOWN,
|
||||
HTTP10,
|
||||
@ -175,7 +175,7 @@ impl de::Deserialize for HttpProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Show, PartialEq, FromPrimitive)]
|
||||
#[derive(Copy, Debug, PartialEq, FromPrimitive)]
|
||||
enum HttpMethod {
|
||||
METHOD_UNKNOWN,
|
||||
GET,
|
||||
@ -223,7 +223,7 @@ impl de::Deserialize for HttpMethod {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Show, PartialEq, FromPrimitive)]
|
||||
#[derive(Copy, Debug, PartialEq, FromPrimitive)]
|
||||
enum CacheStatus {
|
||||
CACHESTATUS_UNKNOWN,
|
||||
Miss,
|
||||
@ -298,7 +298,7 @@ impl de::Deserialize for OriginField {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Show, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
#[derive(Debug, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
#[derive_serialize]
|
||||
//#[derive_deserialize]
|
||||
struct Origin {
|
||||
@ -347,7 +347,7 @@ impl Deserialize for Origin {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Show, PartialEq, FromPrimitive)]
|
||||
#[derive(Copy, Debug, PartialEq, FromPrimitive)]
|
||||
enum OriginProtocol {
|
||||
ORIGIN_PROTOCOL_UNKNOWN,
|
||||
HTTP,
|
||||
@ -387,7 +387,7 @@ impl de::Deserialize for OriginProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Show, PartialEq, FromPrimitive)]
|
||||
#[derive(Copy, Debug, PartialEq, FromPrimitive)]
|
||||
enum ZonePlan {
|
||||
ZONEPLAN_UNKNOWN,
|
||||
FREE,
|
||||
@ -429,7 +429,7 @@ impl de::Deserialize for ZonePlan {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Show, PartialEq, FromPrimitive)]
|
||||
#[derive(Copy, Debug, PartialEq, FromPrimitive)]
|
||||
enum Country {
|
||||
UNKNOWN,
|
||||
A1,
|
||||
@ -772,7 +772,7 @@ impl de::Deserialize for LogField {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Show, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
#[derive(Debug, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
#[derive_serialize]
|
||||
//#[derive_deserialize]
|
||||
struct Log {
|
||||
@ -918,7 +918,7 @@ struct MyMemWriter0 {
|
||||
}
|
||||
|
||||
impl MyMemWriter0 {
|
||||
pub fn with_capacity(cap: uint) -> MyMemWriter0 {
|
||||
pub fn with_capacity(cap: usize) -> MyMemWriter0 {
|
||||
MyMemWriter0 {
|
||||
buf: Vec::with_capacity(cap)
|
||||
}
|
||||
@ -928,7 +928,7 @@ impl MyMemWriter0 {
|
||||
|
||||
impl Writer for MyMemWriter0 {
|
||||
#[inline]
|
||||
fn write(&mut self, buf: &[u8]) -> io::IoResult<()> {
|
||||
fn write_all(&mut self, buf: &[u8]) -> old_io::IoResult<()> {
|
||||
self.buf.push_all(buf);
|
||||
Ok(())
|
||||
}
|
||||
@ -939,7 +939,7 @@ struct MyMemWriter1 {
|
||||
}
|
||||
|
||||
impl MyMemWriter1 {
|
||||
pub fn with_capacity(cap: uint) -> MyMemWriter1 {
|
||||
pub fn with_capacity(cap: usize) -> MyMemWriter1 {
|
||||
MyMemWriter1 {
|
||||
buf: Vec::with_capacity(cap)
|
||||
}
|
||||
@ -960,7 +960,7 @@ fn push_all_bytes(dst: &mut Vec<u8>, src: &[u8]) {
|
||||
dst.set_len(dst_len + src_len);
|
||||
|
||||
::std::ptr::copy_nonoverlapping_memory(
|
||||
dst.as_mut_ptr().offset(dst_len as int),
|
||||
dst.as_mut_ptr().offset(dst_len as isize),
|
||||
src.as_ptr(),
|
||||
src_len);
|
||||
}
|
||||
@ -968,7 +968,7 @@ fn push_all_bytes(dst: &mut Vec<u8>, src: &[u8]) {
|
||||
|
||||
impl Writer for MyMemWriter1 {
|
||||
#[inline]
|
||||
fn write(&mut self, buf: &[u8]) -> io::IoResult<()> {
|
||||
fn write_all(&mut self, buf: &[u8]) -> old_io::IoResult<()> {
|
||||
push_all_bytes(&mut self.buf, buf);
|
||||
Ok(())
|
||||
}
|
||||
@ -982,21 +982,21 @@ fn test_encoder() {
|
||||
|
||||
let log = Log::new();
|
||||
|
||||
let mut wr = Vec::with_capacity(1024);
|
||||
let mut wr = String::with_capacity(1024);
|
||||
|
||||
{
|
||||
let mut encoder = rustc_serialize::json::Encoder::new(&mut wr);
|
||||
log.encode(&mut encoder).unwrap();
|
||||
}
|
||||
|
||||
assert_eq!(wr.as_slice(), JSON_STR.as_bytes());
|
||||
assert_eq!(&wr[], JSON_STR);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_encoder(b: &mut Bencher) {
|
||||
let log = Log::new();
|
||||
|
||||
let mut wr = Vec::with_capacity(1024);
|
||||
let mut wr = String::with_capacity(1024);
|
||||
|
||||
{
|
||||
let mut encoder = rustc_serialize::json::Encoder::new(&mut wr);
|
||||
@ -1039,7 +1039,7 @@ fn test_serializer_vec() {
|
||||
serializer.visit(&log).unwrap();
|
||||
|
||||
let json = serializer.into_inner();
|
||||
assert_eq!(json.as_slice(), JSON_STR.as_bytes());
|
||||
assert_eq!(&json[], JSON_STR.as_bytes());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1069,7 +1069,7 @@ fn bench_serializer_slice(b: &mut Bencher) {
|
||||
|
||||
b.iter(|| {
|
||||
for item in buf.iter_mut(){ *item = 0; }
|
||||
let mut wr = std::io::BufWriter::new(&mut buf);
|
||||
let mut wr = std::old_io::BufWriter::new(&mut buf);
|
||||
|
||||
let mut serializer = json::Writer::new(wr.by_ref());
|
||||
serializer.visit(&log).unwrap();
|
||||
@ -1089,7 +1089,7 @@ fn test_serializer_my_mem_writer0() {
|
||||
let _json = serializer.into_inner();
|
||||
}
|
||||
|
||||
assert_eq!(wr.buf.as_slice(), JSON_STR.as_bytes());
|
||||
assert_eq!(&wr.buf[], JSON_STR.as_bytes());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1121,7 +1121,7 @@ fn test_serializer_my_mem_writer1() {
|
||||
let _json = serializer.into_inner();
|
||||
}
|
||||
|
||||
assert_eq!(wr.buf.as_slice(), JSON_STR.as_bytes());
|
||||
assert_eq!(&wr.buf[], JSON_STR.as_bytes());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1157,10 +1157,10 @@ fn manual_serialize_no_escape<W: Writer>(wr: &mut W, log: &Log) {
|
||||
wr.write_str(",\"zone_id\":").unwrap();
|
||||
(write!(wr, "{}", log.zone_id)).unwrap();
|
||||
wr.write_str(",\"zone_plan\":").unwrap();
|
||||
(write!(wr, "{}", log.zone_plan as uint)).unwrap();
|
||||
(write!(wr, "{}", log.zone_plan as usize)).unwrap();
|
||||
|
||||
wr.write_str(",\"http\":{\"protocol\":").unwrap();
|
||||
(write!(wr, "{}", log.http.protocol as uint)).unwrap();
|
||||
(write!(wr, "{}", log.http.protocol as usize)).unwrap();
|
||||
wr.write_str(",\"status\":").unwrap();
|
||||
(write!(wr, "{}", log.http.status)).unwrap();
|
||||
wr.write_str(",\"host_status\":").unwrap();
|
||||
@ -1168,7 +1168,7 @@ fn manual_serialize_no_escape<W: Writer>(wr: &mut W, log: &Log) {
|
||||
wr.write_str(",\"up_status\":").unwrap();
|
||||
(write!(wr, "{}", log.http.up_status)).unwrap();
|
||||
wr.write_str(",\"method\":").unwrap();
|
||||
(write!(wr, "{}", log.http.method as uint)).unwrap();
|
||||
(write!(wr, "{}", log.http.method as usize)).unwrap();
|
||||
wr.write_str(",\"content_type\":").unwrap();
|
||||
(write!(wr, "\"{}\"", log.http.content_type)).unwrap();
|
||||
wr.write_str(",\"user_agent\":").unwrap();
|
||||
@ -1188,12 +1188,12 @@ fn manual_serialize_no_escape<W: Writer>(wr: &mut W, log: &Log) {
|
||||
(write!(wr, "\"{}\"", log.origin.hostname)).unwrap();
|
||||
|
||||
wr.write_str(",\"protocol\":").unwrap();
|
||||
(write!(wr, "{}", log.origin.protocol as uint)).unwrap();
|
||||
(write!(wr, "{}", log.origin.protocol as usize)).unwrap();
|
||||
|
||||
wr.write_str("},\"country\":").unwrap();
|
||||
(write!(wr, "{}", log.country as uint)).unwrap();
|
||||
(write!(wr, "{}", log.country as usize)).unwrap();
|
||||
wr.write_str(",\"cache_status\":").unwrap();
|
||||
(write!(wr, "{}", log.cache_status as uint)).unwrap();
|
||||
(write!(wr, "{}", log.cache_status as usize)).unwrap();
|
||||
wr.write_str(",\"server_ip\":").unwrap();
|
||||
(write!(wr, "\"{}\"", log.server_ip)).unwrap();
|
||||
wr.write_str(",\"server_name\":").unwrap();
|
||||
@ -1220,14 +1220,14 @@ fn manual_serialize_escape<W: Writer>(wr: &mut W, log: &Log) {
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "zone_plan").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
(write!(wr, "{}", log.zone_plan as int)).unwrap();
|
||||
(write!(wr, "{}", log.zone_plan as isize)).unwrap();
|
||||
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "http").unwrap();
|
||||
wr.write_str(":{").unwrap();
|
||||
escape_str(wr, "protocol").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
(write!(wr, "{}", log.http.protocol as uint)).unwrap();
|
||||
(write!(wr, "{}", log.http.protocol as usize)).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "status").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
@ -1243,23 +1243,23 @@ fn manual_serialize_escape<W: Writer>(wr: &mut W, log: &Log) {
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "method").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
(write!(wr, "{}", log.http.method as uint)).unwrap();
|
||||
(write!(wr, "{}", log.http.method as usize)).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "content_type").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.http.content_type.as_slice()).unwrap();
|
||||
escape_str(wr, &log.http.content_type).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "user_agent").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.http.user_agent.as_slice()).unwrap();
|
||||
escape_str(wr, &log.http.user_agent).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "referer").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.http.referer.as_slice()).unwrap();
|
||||
escape_str(wr, &log.http.referer).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "request_uri").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.http.request_uri.as_slice()).unwrap();
|
||||
escape_str(wr, &log.http.request_uri).unwrap();
|
||||
|
||||
wr.write_str("},").unwrap();
|
||||
escape_str(wr, "origin").unwrap();
|
||||
@ -1267,7 +1267,7 @@ fn manual_serialize_escape<W: Writer>(wr: &mut W, log: &Log) {
|
||||
|
||||
escape_str(wr, "ip").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.origin.ip.as_slice()).unwrap();
|
||||
escape_str(wr, &log.origin.ip).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "port").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
@ -1275,32 +1275,32 @@ fn manual_serialize_escape<W: Writer>(wr: &mut W, log: &Log) {
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "hostname").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.origin.hostname.as_slice()).unwrap();
|
||||
escape_str(wr, &log.origin.hostname).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "protocol").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
(write!(wr, "{}", log.origin.protocol as uint)).unwrap();
|
||||
(write!(wr, "{}", log.origin.protocol as usize)).unwrap();
|
||||
|
||||
wr.write_str("},").unwrap();
|
||||
escape_str(wr, "country").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
(write!(wr, "{}", log.country as uint)).unwrap();
|
||||
(write!(wr, "{}", log.country as usize)).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "cache_status").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
(write!(wr, "{}", log.cache_status as uint)).unwrap();
|
||||
(write!(wr, "{}", log.cache_status as usize)).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "server_ip").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.server_ip.as_slice()).unwrap();
|
||||
escape_str(wr, &log.server_ip).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "server_name").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.server_name.as_slice()).unwrap();
|
||||
escape_str(wr, &log.server_name).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "remote_ip").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.remote_ip.as_slice()).unwrap();
|
||||
escape_str(wr, &log.remote_ip).unwrap();
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "bytes_dlv").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
@ -1309,7 +1309,7 @@ fn manual_serialize_escape<W: Writer>(wr: &mut W, log: &Log) {
|
||||
wr.write_str(",").unwrap();
|
||||
escape_str(wr, "ray_id").unwrap();
|
||||
wr.write_str(":").unwrap();
|
||||
escape_str(wr, log.ray_id.as_slice()).unwrap();
|
||||
escape_str(wr, &log.ray_id).unwrap();
|
||||
wr.write_str("}").unwrap();
|
||||
}
|
||||
|
||||
@ -1321,7 +1321,7 @@ fn test_manual_serialize_vec_no_escape() {
|
||||
manual_serialize_no_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1346,7 +1346,7 @@ fn test_manual_serialize_vec_escape() {
|
||||
manual_serialize_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1372,7 +1372,7 @@ fn test_manual_serialize_my_mem_writer0_no_escape() {
|
||||
manual_serialize_no_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1398,7 +1398,7 @@ fn test_manual_serialize_my_mem_writer0_escape() {
|
||||
manual_serialize_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1424,7 +1424,7 @@ fn test_manual_serialize_my_mem_writer1_no_escape() {
|
||||
manual_serialize_no_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1450,7 +1450,7 @@ fn test_manual_serialize_my_mem_writer1_escape() {
|
||||
manual_serialize_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![feature(plugin_registrar, quote, unboxed_closures)]
|
||||
#![feature(plugin_registrar, quote, unboxed_closures, rustc_private)]
|
||||
|
||||
extern crate syntax;
|
||||
extern crate rustc;
|
||||
@ -73,6 +73,7 @@ fn expand_derive_serialize<>(cx: &mut ExtCtxt,
|
||||
path: Path::new(vec!["serde2", "ser", "Serialize"]),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
associated_types: vec![],
|
||||
methods: vec![
|
||||
MethodDef {
|
||||
name: "visit",
|
||||
@ -260,6 +261,7 @@ pub fn expand_derive_deserialize(cx: &mut ExtCtxt,
|
||||
vec!(Box::new(Literal(Path::new_local("__E")))), true))),
|
||||
("__E", None, vec!()))
|
||||
},
|
||||
associated_types: vec![],
|
||||
methods: vec!(
|
||||
MethodDef {
|
||||
name: "deserialize_token",
|
||||
@ -313,7 +315,7 @@ fn deserialize_substructure(cx: &mut ExtCtxt, span: Span,
|
||||
cx,
|
||||
span,
|
||||
substr.type_ident,
|
||||
fields.as_slice(),
|
||||
&fields,
|
||||
deserializer,
|
||||
token)
|
||||
}
|
||||
@ -400,7 +402,7 @@ fn deserialize_struct_from_map(
|
||||
) -> P<ast::Expr> {
|
||||
let fields = match *fields {
|
||||
Unnamed(_) => fail!(),
|
||||
Named(ref fields) => fields.as_slice(),
|
||||
Named(ref fields) => &fields[],
|
||||
};
|
||||
|
||||
// Declare each field.
|
||||
@ -458,7 +460,7 @@ fn deserialize_struct_from_map(
|
||||
{
|
||||
let key = match token {
|
||||
::serde2::de::Str(s) => s,
|
||||
::serde2::de::String(ref s) => s.as_slice(),
|
||||
::serde2::de::String(ref s) => &s,
|
||||
token => {
|
||||
let expected_tokens = [
|
||||
::serde2::de::StrKind,
|
||||
@ -550,7 +552,7 @@ fn deserialize_static_fields(
|
||||
getarg(
|
||||
cx,
|
||||
span,
|
||||
token::intern_and_get_ident(format!("_field{}", i).as_slice())
|
||||
token::intern_and_get_ident(&format!("_field{}", i))
|
||||
)
|
||||
}).collect();
|
||||
|
||||
|
@ -139,7 +139,7 @@ pub trait Visitor {
|
||||
fn visit_string<
|
||||
E: Error,
|
||||
>(&mut self, v: String) -> Result<Self::Value, E> {
|
||||
self.visit_str(&v[])
|
||||
self.visit_str(&v)
|
||||
}
|
||||
|
||||
fn visit_unit<
|
||||
@ -665,7 +665,7 @@ mod tests {
|
||||
use std::iter;
|
||||
use std::vec;
|
||||
|
||||
#[derive(Show)]
|
||||
#[derive(Debug)]
|
||||
enum Token<'a> {
|
||||
Bool(bool),
|
||||
Isize(isize),
|
||||
@ -704,7 +704,7 @@ mod tests {
|
||||
}
|
||||
|
||||
struct TokenDeserializer<'a> {
|
||||
tokens: iter::Peekable<Token<'a>, vec::IntoIter<Token<'a>>>,
|
||||
tokens: iter::Peekable<vec::IntoIter<Token<'a>>>,
|
||||
}
|
||||
|
||||
impl<'a> TokenDeserializer<'a> {
|
||||
@ -715,7 +715,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, PartialEq, Show)]
|
||||
#[derive(Copy, PartialEq, Debug)]
|
||||
enum Error {
|
||||
SyntaxError,
|
||||
EndOfStreamError,
|
||||
@ -973,7 +973,7 @@ mod tests {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Copy, PartialEq, Show)]
|
||||
#[derive(Copy, PartialEq, Debug)]
|
||||
struct NamedUnit;
|
||||
|
||||
impl Deserialize for NamedUnit {
|
||||
@ -1015,7 +1015,7 @@ mod tests {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(PartialEq, Show)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
struct NamedSeq(i32, i32, i32);
|
||||
|
||||
impl Deserialize for NamedSeq {
|
||||
@ -1067,7 +1067,7 @@ mod tests {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(PartialEq, Show)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
struct NamedMap {
|
||||
a: i32,
|
||||
b: i32,
|
||||
@ -1152,7 +1152,7 @@ mod tests {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(PartialEq, Show)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
enum Enum {
|
||||
Unit,
|
||||
Seq(i32, i32, i32),
|
||||
|
@ -106,7 +106,7 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
|
||||
b'0' ... b'9' | b'-' => self.parse_number(visitor),
|
||||
b'"' => {
|
||||
try!(self.parse_string());
|
||||
let s = str::from_utf8(self.buf.as_slice()).unwrap();
|
||||
let s = str::from_utf8(&self.buf).unwrap();
|
||||
visitor.visit_str(s)
|
||||
}
|
||||
b'[' => {
|
||||
@ -334,7 +334,7 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
|
||||
}
|
||||
|
||||
let buf = &[n1, try!(self.decode_hex_escape())];
|
||||
match ::unicode::str::utf16_items(buf.as_slice()).next() {
|
||||
match ::unicode::str::utf16_items(buf).next() {
|
||||
Some(Utf16Item::ScalarValue(c)) => c,
|
||||
_ => {
|
||||
return Err(self.error(ErrorCode::LoneLeadingSurrogateInHexEscape));
|
||||
@ -352,7 +352,7 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
|
||||
|
||||
let buf = &mut [0; 4];
|
||||
let len = c.encode_utf8(buf).unwrap_or(0);
|
||||
self.buf.extend(buf.slice_to(len).iter().map(|b| *b));
|
||||
self.buf.extend(buf[..len].iter().map(|b| *b));
|
||||
}
|
||||
_ => {
|
||||
return Err(self.error(ErrorCode::InvalidEscape));
|
||||
@ -528,12 +528,11 @@ pub fn from_str<'a, T>(s: &'a str) -> Result<T, Error>
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::str;
|
||||
use std::fmt::Show;
|
||||
use std::fmt::Debug;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use de::Deserialize;
|
||||
use super::{Parser, from_str};
|
||||
use super::from_str;
|
||||
use super::super::error::{Error, ErrorCode};
|
||||
|
||||
macro_rules! treemap {
|
||||
@ -545,9 +544,9 @@ mod tests {
|
||||
}
|
||||
|
||||
fn test_parse_ok<'a, T>(errors: Vec<(&'a str, T)>)
|
||||
where T: PartialEq + Show + Deserialize,
|
||||
where T: PartialEq + Debug + Deserialize,
|
||||
{
|
||||
for (s, value) in errors.into_iter() {
|
||||
for (s, value) in errors {
|
||||
let v: Result<T, Error> = from_str(s);
|
||||
assert_eq!(v, Ok(value));
|
||||
|
||||
@ -559,9 +558,9 @@ mod tests {
|
||||
}
|
||||
|
||||
fn test_parse_err<'a, T>(errors: Vec<(&'a str, Error)>)
|
||||
where T: PartialEq + Show + Deserialize
|
||||
where T: PartialEq + Debug + Deserialize
|
||||
{
|
||||
for (s, err) in errors.into_iter() {
|
||||
for (s, err) in errors {
|
||||
let v: Result<T, Error> = from_str(s);
|
||||
assert_eq!(v, Err(err));
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
use std::old_io;
|
||||
|
||||
use de;
|
||||
|
||||
@ -37,7 +37,7 @@ pub enum ErrorCode {
|
||||
UnrecognizedHex,
|
||||
}
|
||||
|
||||
impl fmt::Show for ErrorCode {
|
||||
impl fmt::Debug for ErrorCode {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
//ErrorCode::ConversionError(ref token) => write!(f, "failed to convert {}", token),
|
||||
@ -75,11 +75,11 @@ impl fmt::Show for ErrorCode {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Show)]
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub enum Error {
|
||||
/// msg, line, col
|
||||
SyntaxError(ErrorCode, usize, usize),
|
||||
IoError(io::IoError),
|
||||
IoError(old_io::IoError),
|
||||
/*
|
||||
ExpectedError(String, String),
|
||||
MissingFieldError(String),
|
||||
@ -91,21 +91,24 @@ impl error::Error for Error {
|
||||
fn description(&self) -> &str {
|
||||
match *self {
|
||||
Error::SyntaxError(..) => "syntax error",
|
||||
Error::IoError(ref error) => error.description(),
|
||||
Error::IoError(_) => "input/output error",
|
||||
/*
|
||||
Error::ExpectedError(ref expected, _) => expected.as_slice(),
|
||||
Error::ExpectedError(ref expected, _) => &expected,
|
||||
Error::MissingFieldError(_) => "missing field",
|
||||
Error::UnknownVariantError(_) => "unknown variant",
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
fn detail(&self) -> Option<String> {
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Error::SyntaxError(ref code, line, col) => {
|
||||
Some(format!("{:?} at line {:?} column {:?}", code, line, col))
|
||||
write!(fmt, "{:?} at line {:?} column {:?}", code, line, col)
|
||||
}
|
||||
Error::IoError(ref error) => error.detail(),
|
||||
Error::IoError(ref error) => fmt::Display::fmt(error, fmt),
|
||||
/*
|
||||
Error::ExpectedError(ref expected, ref found) => {
|
||||
Some(format!("expected {}, found {}", expected, found))
|
||||
@ -121,8 +124,8 @@ impl error::Error for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl error::FromError<io::IoError> for Error {
|
||||
fn from_error(error: io::IoError) -> Error {
|
||||
impl error::FromError<old_io::IoError> for Error {
|
||||
fn from_error(error: old_io::IoError) -> Error {
|
||||
Error::IoError(error)
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use std::f64;
|
||||
use std::io::{self, ByRefWriter, IoError};
|
||||
use std::old_io::{self, ByRefWriter, IoError};
|
||||
use std::num::{Float, FpCategory};
|
||||
use std::string::FromUtf8Error;
|
||||
|
||||
@ -11,7 +11,7 @@ pub struct Writer<W> {
|
||||
writer: W,
|
||||
}
|
||||
|
||||
impl<W: io::Writer> Writer<W> {
|
||||
impl<W: old_io::Writer> Writer<W> {
|
||||
/// Creates a new JSON visitr whose output will be written to the writer
|
||||
/// specified.
|
||||
#[inline]
|
||||
@ -28,7 +28,7 @@ impl<W: io::Writer> Writer<W> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<W: io::Writer> ser::Serializer for Writer<W> {
|
||||
impl<W: old_io::Writer> ser::Serializer for Writer<W> {
|
||||
type Value = ();
|
||||
type Error = IoError;
|
||||
|
||||
@ -44,7 +44,7 @@ struct Visitor<'a, W: 'a> {
|
||||
writer: &'a mut W,
|
||||
}
|
||||
|
||||
impl<'a, W: io::Writer> ser::Visitor for Visitor<'a, W> {
|
||||
impl<'a, W: old_io::Writer> ser::Visitor for Visitor<'a, W> {
|
||||
type Value = ();
|
||||
type Error = IoError;
|
||||
|
||||
@ -188,7 +188,7 @@ impl<'a, W: io::Writer> ser::Visitor for Visitor<'a, W> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn escape_bytes<W: io::Writer>(wr: &mut W, bytes: &[u8]) -> Result<(), IoError> {
|
||||
pub fn escape_bytes<W: old_io::Writer>(wr: &mut W, bytes: &[u8]) -> Result<(), IoError> {
|
||||
try!(wr.write_str("\""));
|
||||
|
||||
let mut start = 0;
|
||||
@ -206,7 +206,7 @@ pub fn escape_bytes<W: io::Writer>(wr: &mut W, bytes: &[u8]) -> Result<(), IoErr
|
||||
};
|
||||
|
||||
if start < i {
|
||||
try!(wr.write(bytes.slice(start, i)));
|
||||
try!(wr.write_all(&bytes[start..i]));
|
||||
}
|
||||
|
||||
try!(wr.write_str(escaped));
|
||||
@ -215,34 +215,34 @@ pub fn escape_bytes<W: io::Writer>(wr: &mut W, bytes: &[u8]) -> Result<(), IoErr
|
||||
}
|
||||
|
||||
if start != bytes.len() {
|
||||
try!(wr.write(bytes.slice_from(start)));
|
||||
try!(wr.write_all(&bytes[start..]));
|
||||
}
|
||||
|
||||
wr.write_str("\"")
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn escape_str<W: io::Writer>(wr: &mut W, value: &str) -> Result<(), IoError> {
|
||||
pub fn escape_str<W: old_io::Writer>(wr: &mut W, value: &str) -> Result<(), IoError> {
|
||||
escape_bytes(wr, value.as_bytes())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn escape_char<W: io::Writer>(wr: &mut W, value: char) -> Result<(), IoError> {
|
||||
pub fn escape_char<W: old_io::Writer>(wr: &mut W, value: char) -> Result<(), IoError> {
|
||||
let mut buf = &mut [0; 4];
|
||||
value.encode_utf8(buf);
|
||||
escape_bytes(wr, buf)
|
||||
}
|
||||
|
||||
fn fmt_f64_or_null<W: io::Writer>(wr: &mut W, value: f64) -> Result<(), IoError> {
|
||||
fn fmt_f64_or_null<W: old_io::Writer>(wr: &mut W, value: f64) -> Result<(), IoError> {
|
||||
match value.classify() {
|
||||
FpCategory::Nan | FpCategory::Infinite => wr.write_str("null"),
|
||||
_ => wr.write_str(f64::to_str_digits(value, 6).as_slice()),
|
||||
_ => wr.write_str(&f64::to_str_digits(value, 6)),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn to_writer<W, T>(wr: &mut W, value: &T) -> Result<(), IoError>
|
||||
where W: io::Writer,
|
||||
where W: old_io::Writer,
|
||||
T: ser::Serialize,
|
||||
{
|
||||
let mut wr = Writer::new(wr.by_ref());
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
use std::old_io;
|
||||
use std::str;
|
||||
|
||||
use ser::{self, Serializer};
|
||||
@ -35,7 +35,7 @@ impl ser::Serialize for Value {
|
||||
visitor.visit_f64(v)
|
||||
}
|
||||
Value::String(ref v) => {
|
||||
visitor.visit_str(v.as_slice())
|
||||
visitor.visit_str(&v)
|
||||
}
|
||||
Value::Array(ref v) => {
|
||||
v.visit(visitor)
|
||||
@ -51,13 +51,13 @@ struct WriterFormatter<'a, 'b: 'a> {
|
||||
inner: &'a mut fmt::Formatter<'b>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> io::Writer for WriterFormatter<'a, 'b> {
|
||||
fn write(&mut self, buf: &[u8]) -> io::IoResult<()> {
|
||||
self.inner.write_str(str::from_utf8(buf).unwrap()).map_err(|_| io::IoError::last_error())
|
||||
impl<'a, 'b> old_io::Writer for WriterFormatter<'a, 'b> {
|
||||
fn write_all(&mut self, buf: &[u8]) -> old_io::IoResult<()> {
|
||||
self.inner.write_str(str::from_utf8(buf).unwrap()).map_err(|_| old_io::IoError::last_error())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Show for Value {
|
||||
impl fmt::Debug for Value {
|
||||
/// Serializes a json value into a string
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let mut wr = WriterFormatter { inner: f };
|
||||
|
@ -1,3 +1,5 @@
|
||||
#![feature(io)]
|
||||
|
||||
extern crate unicode;
|
||||
|
||||
//pub use ser::{Serialize, Serializer};
|
||||
|
@ -239,7 +239,7 @@ impl Serialize for String {
|
||||
fn visit<
|
||||
V: Visitor,
|
||||
>(&self, visitor: &mut V) -> Result<V::Value, V::Error> {
|
||||
self.as_slice().visit(visitor)
|
||||
(&self[]).visit(visitor)
|
||||
}
|
||||
}
|
||||
|
||||
@ -321,7 +321,7 @@ impl<
|
||||
fn visit<
|
||||
V: Visitor,
|
||||
>(&self, visitor: &mut V) -> Result<V::Value, V::Error> {
|
||||
self.as_slice().visit(visitor)
|
||||
(&self[]).visit(visitor)
|
||||
}
|
||||
}
|
||||
|
||||
@ -651,7 +651,7 @@ mod tests {
|
||||
use std::vec;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[derive(Clone, PartialEq, Show)]
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub enum Token<'a> {
|
||||
Bool(bool),
|
||||
Isize(isize),
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![crate_name = "serde_macros"]
|
||||
#![crate_type = "dylib"]
|
||||
|
||||
#![feature(plugin_registrar, quote, unboxed_closures)]
|
||||
#![feature(plugin_registrar, quote, unboxed_closures, rustc_private)]
|
||||
|
||||
extern crate syntax;
|
||||
extern crate rustc;
|
||||
@ -110,7 +110,8 @@ fn expand_derive_serialize(cx: &mut ExtCtxt,
|
||||
combine_substructure: combine_substructure(Box::new( |a, b, c| {
|
||||
serialize_substructure(a, b, c, item)
|
||||
})),
|
||||
})
|
||||
}),
|
||||
associated_types: vec!()
|
||||
};
|
||||
|
||||
trait_def.expand(cx, mitem, item, |item| push.call_mut((item,)))
|
||||
@ -142,7 +143,7 @@ fn serialize_substructure(cx: &ExtCtxt,
|
||||
let name = match (serial_name, name) {
|
||||
(Some(serial), _) => serial.clone(),
|
||||
(None, Some(id)) => token::get_ident(id),
|
||||
(None, None) => token::intern_and_get_ident(format!("_field{}", i).as_slice()),
|
||||
(None, None) => token::intern_and_get_ident(&format!("_field{}", i)),
|
||||
};
|
||||
|
||||
let name = cx.expr_str(span, name);
|
||||
@ -241,7 +242,8 @@ pub fn expand_derive_deserialize(cx: &mut ExtCtxt,
|
||||
combine_substructure: combine_substructure(Box::new(|a, b, c| {
|
||||
deserialize_substructure(a, b, c)
|
||||
})),
|
||||
})
|
||||
}),
|
||||
associated_types: vec!()
|
||||
};
|
||||
|
||||
trait_def.expand(cx, mitem, item, |item| push.call_mut((item,)))
|
||||
@ -259,7 +261,7 @@ fn deserialize_substructure(cx: &mut ExtCtxt,
|
||||
cx,
|
||||
span,
|
||||
substr.type_ident,
|
||||
definition.fields.as_slice(),
|
||||
&definition.fields,
|
||||
fields,
|
||||
deserializer.clone(),
|
||||
token)
|
||||
@ -269,8 +271,8 @@ fn deserialize_substructure(cx: &mut ExtCtxt,
|
||||
cx,
|
||||
span,
|
||||
substr.type_ident,
|
||||
definition.variants.as_slice(),
|
||||
fields.as_slice(),
|
||||
&definition.variants,
|
||||
&fields,
|
||||
deserializer,
|
||||
token)
|
||||
}
|
||||
@ -291,14 +293,14 @@ fn deserialize_struct(
|
||||
|
||||
let fields = match *fields {
|
||||
Unnamed(_) => panic!(),
|
||||
Named(ref fields) => fields.as_slice(),
|
||||
Named(ref fields) => &fields[],
|
||||
};
|
||||
|
||||
// Convert each field into a unique ident.
|
||||
let field_idents: Vec<ast::Ident> = fields.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, _)| {
|
||||
cx.ident_of(format!("field{}", idx).as_slice())
|
||||
cx.ident_of(&format!("field{}", idx))
|
||||
})
|
||||
.collect();
|
||||
|
||||
@ -413,7 +415,7 @@ fn deserialize_enum(
|
||||
cx,
|
||||
span,
|
||||
path,
|
||||
serial_names.as_slice(),
|
||||
&serial_names,
|
||||
parts,
|
||||
|&: cx, _, _| {
|
||||
quote_expr!(cx, try!($deserializer.expect_enum_elt()))
|
||||
@ -459,7 +461,7 @@ fn deserialize_static_fields<F>(
|
||||
getarg(
|
||||
cx,
|
||||
span,
|
||||
token::intern_and_get_ident(format!("_field{}", i).as_slice())
|
||||
token::intern_and_get_ident(&format!("_field{}", i))
|
||||
)
|
||||
}).collect();
|
||||
|
||||
@ -486,7 +488,7 @@ fn deserialize_static_fields<F>(
|
||||
}
|
||||
}
|
||||
|
||||
fn find_serial_name<'a, I>(mut iterator: I) -> Option<token::InternedString> where
|
||||
fn find_serial_name<'a, I>(iterator: I) -> Option<token::InternedString> where
|
||||
I: Iterator<Item=&'a Attribute>
|
||||
{
|
||||
for at in iterator {
|
||||
|
136
src/de.rs
136
src/de.rs
@ -18,16 +18,16 @@ use std::rc::Rc;
|
||||
use std::string;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone, PartialEq, Show)]
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub enum Token {
|
||||
Null,
|
||||
Bool(bool),
|
||||
Int(int),
|
||||
Isize(isize),
|
||||
I8(i8),
|
||||
I16(i16),
|
||||
I32(i32),
|
||||
I64(i64),
|
||||
Uint(uint),
|
||||
Usize(usize),
|
||||
U8(u8),
|
||||
U16(u16),
|
||||
U32(u32),
|
||||
@ -39,11 +39,11 @@ pub enum Token {
|
||||
String(String),
|
||||
Option(bool),
|
||||
|
||||
TupleStart(uint),
|
||||
StructStart(&'static str, uint),
|
||||
EnumStart(&'static str, &'static str, uint),
|
||||
SeqStart(uint),
|
||||
MapStart(uint),
|
||||
TupleStart(usize),
|
||||
StructStart(&'static str, usize),
|
||||
EnumStart(&'static str, &'static str, usize),
|
||||
SeqStart(usize),
|
||||
MapStart(usize),
|
||||
|
||||
End,
|
||||
}
|
||||
@ -53,12 +53,12 @@ impl Token {
|
||||
match *self {
|
||||
Token::Null => TokenKind::NullKind,
|
||||
Token::Bool(_) => TokenKind::BoolKind,
|
||||
Token::Int(_) => TokenKind::IntKind,
|
||||
Token::Isize(_) => TokenKind::IsizeKind,
|
||||
Token::I8(_) => TokenKind::I8Kind,
|
||||
Token::I16(_) => TokenKind::I16Kind,
|
||||
Token::I32(_) => TokenKind::I32Kind,
|
||||
Token::I64(_) => TokenKind::I64Kind,
|
||||
Token::Uint(_) => TokenKind::UintKind,
|
||||
Token::Usize(_) => TokenKind::UsizeKind,
|
||||
Token::U8(_) => TokenKind::U8Kind,
|
||||
Token::U16(_) => TokenKind::U16Kind,
|
||||
Token::U32(_) => TokenKind::U32Kind,
|
||||
@ -83,12 +83,12 @@ impl Token {
|
||||
pub enum TokenKind {
|
||||
NullKind,
|
||||
BoolKind,
|
||||
IntKind,
|
||||
IsizeKind,
|
||||
I8Kind,
|
||||
I16Kind,
|
||||
I32Kind,
|
||||
I64Kind,
|
||||
UintKind,
|
||||
UsizeKind,
|
||||
U8Kind,
|
||||
U16Kind,
|
||||
U32Kind,
|
||||
@ -110,12 +110,12 @@ pub enum TokenKind {
|
||||
}
|
||||
|
||||
static PRIMITIVE_TOKEN_KINDS: &'static [TokenKind] = &[
|
||||
TokenKind::IntKind,
|
||||
TokenKind::IsizeKind,
|
||||
TokenKind::I8Kind,
|
||||
TokenKind::I16Kind,
|
||||
TokenKind::I32Kind,
|
||||
TokenKind::I64Kind,
|
||||
TokenKind::UintKind,
|
||||
TokenKind::UsizeKind,
|
||||
TokenKind::U8Kind,
|
||||
TokenKind::U16Kind,
|
||||
TokenKind::U32Kind,
|
||||
@ -138,17 +138,17 @@ static COMPOUND_TOKEN_KINDS: &'static [TokenKind] = &[
|
||||
TokenKind::MapStartKind,
|
||||
];
|
||||
|
||||
impl ::std::fmt::Show for TokenKind {
|
||||
impl ::std::fmt::Debug for TokenKind {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
match *self {
|
||||
TokenKind::NullKind => "Null".fmt(f),
|
||||
TokenKind::BoolKind => "Bool".fmt(f),
|
||||
TokenKind::IntKind => "Int".fmt(f),
|
||||
TokenKind::IsizeKind => "Isize".fmt(f),
|
||||
TokenKind::I8Kind => "I8".fmt(f),
|
||||
TokenKind::I16Kind => "I16".fmt(f),
|
||||
TokenKind::I32Kind => "I32".fmt(f),
|
||||
TokenKind::I64Kind => "I64".fmt(f),
|
||||
TokenKind::UintKind => "Uint".fmt(f),
|
||||
TokenKind::UsizeKind => "Usize".fmt(f),
|
||||
TokenKind::U8Kind => "U8".fmt(f),
|
||||
TokenKind::U16Kind => "U16".fmt(f),
|
||||
TokenKind::U32Kind => "U32".fmt(f),
|
||||
@ -253,12 +253,12 @@ pub trait Deserializer<E>: Iterator<Item=Result<Token, E>> + Sized {
|
||||
#[inline]
|
||||
fn expect_num<T: num::NumCast>(&mut self, token: Token) -> Result<T, E> {
|
||||
match token {
|
||||
Token::Int(x) => to_result!(num::cast(x), self.syntax_error(token, PRIMITIVE_TOKEN_KINDS)),
|
||||
Token::Isize(x) => to_result!(num::cast(x), self.syntax_error(token, PRIMITIVE_TOKEN_KINDS)),
|
||||
Token::I8(x) => to_result!(num::cast(x), self.syntax_error(token, PRIMITIVE_TOKEN_KINDS)),
|
||||
Token::I16(x) => to_result!(num::cast(x), self.syntax_error(token, PRIMITIVE_TOKEN_KINDS)),
|
||||
Token::I32(x) => to_result!(num::cast(x), self.syntax_error(token, PRIMITIVE_TOKEN_KINDS)),
|
||||
Token::I64(x) => to_result!(num::cast(x), self.syntax_error(token, PRIMITIVE_TOKEN_KINDS)),
|
||||
Token::Uint(x) => to_result!(num::cast(x), self.syntax_error(token, PRIMITIVE_TOKEN_KINDS)),
|
||||
Token::Usize(x) => to_result!(num::cast(x), self.syntax_error(token, PRIMITIVE_TOKEN_KINDS)),
|
||||
Token::U8(x) => to_result!(num::cast(x), self.syntax_error(token, PRIMITIVE_TOKEN_KINDS)),
|
||||
Token::U16(x) => to_result!(num::cast(x), self.syntax_error(token, PRIMITIVE_TOKEN_KINDS)),
|
||||
Token::U32(x) => to_result!(num::cast(x), self.syntax_error(token, PRIMITIVE_TOKEN_KINDS)),
|
||||
@ -272,12 +272,12 @@ pub trait Deserializer<E>: Iterator<Item=Result<Token, E>> + Sized {
|
||||
#[inline]
|
||||
fn expect_from_primitive<T: FromPrimitive>(&mut self, token: Token) -> Result<T, E> {
|
||||
match token {
|
||||
Token::Int(x) => to_result!(num::from_int(x), self.conversion_error(token)),
|
||||
Token::Isize(x) => to_result!(num::from_int(x), self.conversion_error(token)),
|
||||
Token::I8(x) => to_result!(num::from_i8(x), self.conversion_error(token)),
|
||||
Token::I16(x) => to_result!(num::from_i16(x), self.conversion_error(token)),
|
||||
Token::I32(x) => to_result!(num::from_i32(x), self.conversion_error(token)),
|
||||
Token::I64(x) => to_result!(num::from_i64(x), self.conversion_error(token)),
|
||||
Token::Uint(x) => to_result!(num::from_uint(x), self.conversion_error(token)),
|
||||
Token::Usize(x) => to_result!(num::from_uint(x), self.conversion_error(token)),
|
||||
Token::U8(x) => to_result!(num::from_u8(x), self.conversion_error(token)),
|
||||
Token::U16(x) => to_result!(num::from_u16(x), self.conversion_error(token)),
|
||||
Token::U32(x) => to_result!(num::from_u32(x), self.conversion_error(token)),
|
||||
@ -295,8 +295,8 @@ pub trait Deserializer<E>: Iterator<Item=Result<Token, E>> + Sized {
|
||||
Token::Str(value) if value.chars().count() == 1 => {
|
||||
Ok(value.char_at(0))
|
||||
}
|
||||
Token::String(ref value) if value.as_slice().chars().count() == 1 => {
|
||||
Ok(value.as_slice().char_at(0))
|
||||
Token::String(ref value) if value[].chars().count() == 1 => {
|
||||
Ok(value[].char_at(0))
|
||||
}
|
||||
token => {
|
||||
static EXPECTED_TOKENS: &'static [TokenKind] = &[
|
||||
@ -345,7 +345,7 @@ pub trait Deserializer<E>: Iterator<Item=Result<Token, E>> + Sized {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn expect_tuple_start(&mut self, token: Token) -> Result<uint, E> {
|
||||
fn expect_tuple_start(&mut self, token: Token) -> Result<usize, E> {
|
||||
match token {
|
||||
Token::TupleStart(len) => Ok(len),
|
||||
Token::SeqStart(len) => Ok(len),
|
||||
@ -401,7 +401,7 @@ pub trait Deserializer<E>: Iterator<Item=Result<Token, E>> + Sized {
|
||||
#[inline]
|
||||
fn expect_struct_field_or_end(&mut self,
|
||||
fields: &'static [&'static str]
|
||||
) -> Result<option::Option<option::Option<uint>>, E> {
|
||||
) -> Result<option::Option<option::Option<usize>>, E> {
|
||||
match try!(self.expect_token()) {
|
||||
Token::End => {
|
||||
Ok(None)
|
||||
@ -410,7 +410,7 @@ pub trait Deserializer<E>: Iterator<Item=Result<Token, E>> + Sized {
|
||||
Ok(Some(fields.iter().position(|field| *field == n)))
|
||||
}
|
||||
Token::String(n) => {
|
||||
Ok(Some(fields.iter().position(|field| *field == n.as_slice())))
|
||||
Ok(Some(fields.iter().position(|field| *field == &n[])))
|
||||
}
|
||||
token => {
|
||||
Err(self.syntax_error(token, STR_TOKEN_KINDS))
|
||||
@ -439,7 +439,7 @@ pub trait Deserializer<E>: Iterator<Item=Result<Token, E>> + Sized {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn expect_enum_start(&mut self, token: Token, name: &str, variants: &[&str]) -> Result<uint, E> {
|
||||
fn expect_enum_start(&mut self, token: Token, name: &str, variants: &[&str]) -> Result<usize, E> {
|
||||
match token {
|
||||
Token::EnumStart(n, v, _) => {
|
||||
if name == n {
|
||||
@ -481,7 +481,7 @@ pub trait Deserializer<E>: Iterator<Item=Result<Token, E>> + Sized {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn expect_seq_start(&mut self, token: Token) -> Result<uint, E> {
|
||||
fn expect_seq_start(&mut self, token: Token) -> Result<usize, E> {
|
||||
match token {
|
||||
Token::TupleStart(len) => Ok(len),
|
||||
Token::SeqStart(len) => Ok(len),
|
||||
@ -533,7 +533,7 @@ pub trait Deserializer<E>: Iterator<Item=Result<Token, E>> + Sized {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn expect_map_start(&mut self, token: Token) -> Result<uint, E> {
|
||||
fn expect_map_start(&mut self, token: Token) -> Result<usize, E> {
|
||||
match token {
|
||||
Token::MapStart(len) => Ok(len),
|
||||
_ => {
|
||||
@ -590,7 +590,7 @@ pub trait Deserializer<E>: Iterator<Item=Result<Token, E>> + Sized {
|
||||
|
||||
struct SeqDeserializer<'a, D: 'a, E: 'a, T> {
|
||||
d: &'a mut D,
|
||||
len: uint,
|
||||
len: usize,
|
||||
err: &'a mut Option<E>,
|
||||
}
|
||||
|
||||
@ -617,7 +617,7 @@ impl<
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn size_hint(&self) -> (uint, option::Option<uint>) {
|
||||
fn size_hint(&self) -> (usize, option::Option<usize>) {
|
||||
(self.len, Some(self.len))
|
||||
}
|
||||
}
|
||||
@ -626,7 +626,7 @@ impl<
|
||||
|
||||
struct MapDeserializer<'a, D:'a, E: 'a, K, V> {
|
||||
d: &'a mut D,
|
||||
len: uint,
|
||||
len: usize,
|
||||
err: &'a mut option::Option<E>,
|
||||
}
|
||||
|
||||
@ -651,7 +651,7 @@ impl<
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn size_hint(&self) -> (uint, option::Option<uint>) {
|
||||
fn size_hint(&self) -> (usize, option::Option<usize>) {
|
||||
(self.len, Some(self.len))
|
||||
}
|
||||
}
|
||||
@ -682,12 +682,12 @@ macro_rules! impl_deserialize {
|
||||
}
|
||||
|
||||
impl_deserialize!(bool, expect_bool);
|
||||
impl_deserialize!(int, expect_num);
|
||||
impl_deserialize!(isize, expect_num);
|
||||
impl_deserialize!(i8, expect_num);
|
||||
impl_deserialize!(i16, expect_num);
|
||||
impl_deserialize!(i32, expect_num);
|
||||
impl_deserialize!(i64, expect_num);
|
||||
impl_deserialize!(uint, expect_num);
|
||||
impl_deserialize!(usize, expect_num);
|
||||
impl_deserialize!(u8, expect_num);
|
||||
impl_deserialize!(u16, expect_num);
|
||||
impl_deserialize!(u32, expect_num);
|
||||
@ -1091,10 +1091,10 @@ mod tests {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Clone, PartialEq, Show, RustcDecodable)]
|
||||
#[derive(Clone, PartialEq, Debug, RustcDecodable)]
|
||||
struct Inner {
|
||||
a: (),
|
||||
b: uint,
|
||||
b: usize,
|
||||
c: BTreeMap<string::String, option::Option<char>>,
|
||||
}
|
||||
|
||||
@ -1133,7 +1133,7 @@ mod tests {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Clone, PartialEq, Show, RustcDecodable)]
|
||||
#[derive(Clone, PartialEq, Debug, RustcDecodable)]
|
||||
struct Outer {
|
||||
inner: Vec<Inner>,
|
||||
}
|
||||
@ -1166,10 +1166,10 @@ mod tests {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Clone, PartialEq, Show, RustcDecodable)]
|
||||
#[derive(Clone, PartialEq, Debug, RustcDecodable)]
|
||||
enum Animal {
|
||||
Dog,
|
||||
Frog(string::String, int)
|
||||
Frog(string::String, isize)
|
||||
}
|
||||
|
||||
impl<D: Deserializer<E>, E> Deserialize<D, E> for Animal {
|
||||
@ -1193,7 +1193,7 @@ mod tests {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Show)]
|
||||
#[derive(Debug)]
|
||||
enum Error {
|
||||
EndOfStream,
|
||||
SyntaxError(Vec<TokenKind>),
|
||||
@ -1271,12 +1271,12 @@ mod tests {
|
||||
vec!(Token::Null) => (), (),
|
||||
vec!(Token::Bool(true)) => true, bool,
|
||||
vec!(Token::Bool(false)) => false, bool,
|
||||
vec!(Token::Int(5)) => 5, int,
|
||||
vec!(Token::Isize(5)) => 5, isize,
|
||||
vec!(Token::I8(5)) => 5, i8,
|
||||
vec!(Token::I16(5)) => 5, i16,
|
||||
vec!(Token::I32(5)) => 5, i32,
|
||||
vec!(Token::I64(5)) => 5, i64,
|
||||
vec!(Token::Uint(5)) => 5, uint,
|
||||
vec!(Token::Usize(5)) => 5, usize,
|
||||
vec!(Token::U8(5)) => 5, u8,
|
||||
vec!(Token::U16(5)) => 5, u16,
|
||||
vec!(Token::U32(5)) => 5, u32,
|
||||
@ -1296,11 +1296,11 @@ mod tests {
|
||||
|
||||
vec!(
|
||||
Token::TupleStart(2),
|
||||
Token::Int(5),
|
||||
Token::Isize(5),
|
||||
|
||||
Token::Str("a"),
|
||||
Token::End,
|
||||
) => (5, "a"), (int, &'static str),
|
||||
) => (5, "a"), (isize, &'static str),
|
||||
|
||||
vec!(
|
||||
Token::TupleStart(3),
|
||||
@ -1310,21 +1310,21 @@ mod tests {
|
||||
Token::End,
|
||||
|
||||
Token::TupleStart(2),
|
||||
Token::Int(5),
|
||||
Token::Isize(5),
|
||||
|
||||
Token::Str("a"),
|
||||
Token::End,
|
||||
Token::End,
|
||||
) => ((), (), (5, "a")), ((), (), (int, &'static str))
|
||||
) => ((), (), (5, "a")), ((), (), (isize, &'static str))
|
||||
]);
|
||||
|
||||
test_value!(test_options, [
|
||||
vec!(Token::Option(false)) => None, option::Option<int>,
|
||||
vec!(Token::Option(false)) => None, option::Option<isize>,
|
||||
|
||||
vec!(
|
||||
Token::Option(true),
|
||||
Token::Int(5),
|
||||
) => Some(5), option::Option<int>
|
||||
Token::Isize(5),
|
||||
) => Some(5), option::Option<isize>
|
||||
]);
|
||||
|
||||
test_value!(test_structs, [
|
||||
@ -1345,7 +1345,7 @@ mod tests {
|
||||
Token::Null,
|
||||
|
||||
Token::Str("b"),
|
||||
Token::Uint(5),
|
||||
Token::Usize(5),
|
||||
|
||||
Token::Str("c"),
|
||||
Token::MapStart(1),
|
||||
@ -1377,7 +1377,7 @@ mod tests {
|
||||
vec!(
|
||||
Token::EnumStart("Animal", "Frog", 2),
|
||||
Token::String("Henry".to_string()),
|
||||
Token::Int(349),
|
||||
Token::Isize(349),
|
||||
Token::End,
|
||||
) => Animal::Frog("Henry".to_string(), 349), Animal
|
||||
]);
|
||||
@ -1386,57 +1386,57 @@ mod tests {
|
||||
vec!(
|
||||
Token::SeqStart(0),
|
||||
Token::End,
|
||||
) => vec!(), Vec<int>,
|
||||
) => vec!(), Vec<isize>,
|
||||
|
||||
vec!(
|
||||
Token::SeqStart(3),
|
||||
Token::Int(5),
|
||||
Token::Isize(5),
|
||||
|
||||
Token::Int(6),
|
||||
Token::Isize(6),
|
||||
|
||||
Token::Int(7),
|
||||
Token::Isize(7),
|
||||
Token::End,
|
||||
) => vec!(5, 6, 7), Vec<int>,
|
||||
) => vec!(5, 6, 7), Vec<isize>,
|
||||
|
||||
|
||||
vec!(
|
||||
Token::SeqStart(3),
|
||||
Token::SeqStart(1),
|
||||
Token::Int(1),
|
||||
Token::Isize(1),
|
||||
Token::End,
|
||||
|
||||
Token::SeqStart(2),
|
||||
Token::Int(2),
|
||||
Token::Isize(2),
|
||||
|
||||
Token::Int(3),
|
||||
Token::Isize(3),
|
||||
Token::End,
|
||||
|
||||
Token::SeqStart(3),
|
||||
Token::Int(4),
|
||||
Token::Isize(4),
|
||||
|
||||
Token::Int(5),
|
||||
Token::Isize(5),
|
||||
|
||||
Token::Int(6),
|
||||
Token::Isize(6),
|
||||
Token::End,
|
||||
Token::End,
|
||||
) => vec!(vec!(1), vec!(2, 3), vec!(4, 5, 6)), Vec<Vec<int>>
|
||||
) => vec!(vec!(1), vec!(2, 3), vec!(4, 5, 6)), Vec<Vec<isize>>
|
||||
]);
|
||||
|
||||
test_value!(test_treemaps, [
|
||||
vec!(
|
||||
Token::MapStart(0),
|
||||
Token::End,
|
||||
) => treemap!(), BTreeMap<int, string::String>,
|
||||
) => treemap!(), BTreeMap<isize, string::String>,
|
||||
|
||||
vec!(
|
||||
Token::MapStart(2),
|
||||
Token::Int(5),
|
||||
Token::Isize(5),
|
||||
Token::String("a".to_string()),
|
||||
|
||||
Token::Int(6),
|
||||
Token::Isize(6),
|
||||
Token::String("b".to_string()),
|
||||
Token::End,
|
||||
) => treemap!(5i => "a".to_string(), 6i => "b".to_string()), BTreeMap<int, string::
|
||||
) => treemap!(5is => "a".to_string(), 6is => "b".to_string()), BTreeMap<isize, string::
|
||||
String>
|
||||
]);
|
||||
}
|
||||
|
@ -93,22 +93,22 @@ mod tests {
|
||||
assert_eq!(value, Value::Array(Vec::new()));
|
||||
|
||||
let value = ArrayBuilder::new()
|
||||
.push(1i)
|
||||
.push(2i)
|
||||
.push(3i)
|
||||
.push(1is)
|
||||
.push(2is)
|
||||
.push(3is)
|
||||
.unwrap();
|
||||
assert_eq!(value, Value::Array(vec!(Value::Integer(1), Value::Integer(2), Value::Integer(3))));
|
||||
|
||||
let value = ArrayBuilder::new()
|
||||
.push_array(|bld| bld.push(1i).push(2i).push(3i))
|
||||
.push_array(|bld| bld.push(1is).push(2is).push(3is))
|
||||
.unwrap();
|
||||
assert_eq!(value, Value::Array(vec!(Value::Array(vec!(Value::Integer(1), Value::Integer(2), Value::Integer(3))))));
|
||||
|
||||
let value = ArrayBuilder::new()
|
||||
.push_object(|bld|
|
||||
bld
|
||||
.insert("a".to_string(), 1i)
|
||||
.insert("b".to_string(), 2i))
|
||||
.insert("a".to_string(), 1is)
|
||||
.insert("b".to_string(), 2is))
|
||||
.unwrap();
|
||||
|
||||
let mut map = BTreeMap::new();
|
||||
@ -123,8 +123,8 @@ mod tests {
|
||||
assert_eq!(value, Value::Object(BTreeMap::new()));
|
||||
|
||||
let value = ObjectBuilder::new()
|
||||
.insert("a".to_string(), 1i)
|
||||
.insert("b".to_string(), 2i)
|
||||
.insert("a".to_string(), 1is)
|
||||
.insert("b".to_string(), 2is)
|
||||
.unwrap();
|
||||
|
||||
let mut map = BTreeMap::new();
|
||||
|
@ -7,7 +7,7 @@ use de;
|
||||
|
||||
use super::error::{Error, ErrorCode};
|
||||
|
||||
#[derive(PartialEq, Show)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
enum State {
|
||||
// Parse a value.
|
||||
Value,
|
||||
@ -30,8 +30,8 @@ enum State {
|
||||
pub struct Parser<Iter> {
|
||||
rdr: Iter,
|
||||
ch: Option<u8>,
|
||||
line: uint,
|
||||
col: uint,
|
||||
line: usize,
|
||||
col: usize,
|
||||
// A state machine is kept to make it possible to interupt and resume parsing.
|
||||
state_stack: Vec<State>,
|
||||
buf: Vec<u8>,
|
||||
@ -261,7 +261,7 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
|
||||
match self.ch_or_null() {
|
||||
c @ b'0' ... b'9' => {
|
||||
dec /= 10.0;
|
||||
res += (((c as int) - (b'0' as int)) as f64) * dec;
|
||||
res += (((c as isize) - (b'0' as isize)) as f64) * dec;
|
||||
self.bump();
|
||||
}
|
||||
_ => break,
|
||||
@ -275,7 +275,7 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
|
||||
fn parse_exponent(&mut self, mut res: f64) -> Result<f64, Error> {
|
||||
self.bump();
|
||||
|
||||
let mut exp = 0u;
|
||||
let mut exp = 0us;
|
||||
let mut neg_exp = false;
|
||||
|
||||
if self.ch_is(b'+') {
|
||||
@ -294,7 +294,7 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
|
||||
match self.ch_or_null() {
|
||||
c @ b'0' ... b'9' => {
|
||||
exp *= 10;
|
||||
exp += (c as uint) - (b'0' as uint);
|
||||
exp += (c as usize) - (b'0' as usize);
|
||||
|
||||
self.bump();
|
||||
}
|
||||
@ -314,9 +314,9 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
|
||||
|
||||
#[inline]
|
||||
fn decode_hex_escape(&mut self) -> Result<u16, Error> {
|
||||
let mut i = 0u;
|
||||
let mut i = 0us;
|
||||
let mut n = 0u16;
|
||||
while i < 4u && !self.eof() {
|
||||
while i < 4us && !self.eof() {
|
||||
self.bump();
|
||||
n = match self.ch_or_null() {
|
||||
c @ b'0' ... b'9' => n * 16_u16 + ((c as u16) - (b'0' as u16)),
|
||||
@ -329,11 +329,11 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
|
||||
_ => { return Err(self.error(ErrorCode::InvalidEscape)); }
|
||||
};
|
||||
|
||||
i += 1u;
|
||||
i += 1us;
|
||||
}
|
||||
|
||||
// Error out if we didn't parse 4 digits.
|
||||
if i != 4u {
|
||||
if i != 4us {
|
||||
return Err(self.error(ErrorCode::InvalidEscape));
|
||||
}
|
||||
|
||||
@ -381,7 +381,7 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
|
||||
}
|
||||
|
||||
let buf = &[n1, try!(self.decode_hex_escape())];
|
||||
match ::unicode::str::utf16_items(buf.as_slice()).next() {
|
||||
match ::unicode::str::utf16_items(buf).next() {
|
||||
Some(Utf16Item::ScalarValue(c)) => c,
|
||||
_ => {
|
||||
return Err(self.error(ErrorCode::LoneLeadingSurrogateInHexEscape));
|
||||
@ -399,7 +399,7 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
|
||||
|
||||
let buf = &mut [0u8; 4];
|
||||
let len = c.encode_utf8(buf).unwrap_or(0);
|
||||
self.buf.extend(buf.slice_to(len).iter().map(|b| *b));
|
||||
self.buf.extend(buf[..len].iter().map(|b| *b));
|
||||
}
|
||||
_ => {
|
||||
return Err(self.error(ErrorCode::InvalidEscape));
|
||||
@ -410,7 +410,7 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
|
||||
match ch {
|
||||
b'"' => {
|
||||
self.bump();
|
||||
return Ok(str::from_utf8(self.buf.as_slice()).unwrap());
|
||||
return Ok(str::from_utf8(&self.buf).unwrap());
|
||||
}
|
||||
b'\\' => {
|
||||
escape = true;
|
||||
@ -562,7 +562,7 @@ impl<Iter: Iterator<Item=u8>> de::Deserializer<Error> for Parser<Iter> {
|
||||
fn expect_enum_start(&mut self,
|
||||
token: de::Token,
|
||||
_name: &str,
|
||||
variants: &[&str]) -> Result<uint, Error> {
|
||||
variants: &[&str]) -> Result<usize, Error> {
|
||||
match token {
|
||||
de::Token::MapStart(_) => { }
|
||||
_ => { return Err(self.error(ErrorCode::ExpectedEnumMapStart)); }
|
||||
@ -580,7 +580,7 @@ impl<Iter: Iterator<Item=u8>> de::Deserializer<Error> for Parser<Iter> {
|
||||
_ => { return Err(self.error(ErrorCode::ExpectedEnumToken)); }
|
||||
}
|
||||
|
||||
match variants.iter().position(|v| *v == variant.as_slice()) {
|
||||
match variants.iter().position(|v| *v == &variant[]) {
|
||||
Some(idx) => Ok(idx),
|
||||
None => Err(self.error(ErrorCode::UnknownVariant)),
|
||||
}
|
||||
@ -615,7 +615,7 @@ impl<Iter: Iterator<Item=u8>> de::Deserializer<Error> for Parser<Iter> {
|
||||
#[inline]
|
||||
fn expect_struct_field_or_end(&mut self,
|
||||
fields: &'static [&'static str]
|
||||
) -> Result<Option<Option<uint>>, Error> {
|
||||
) -> Result<Option<Option<usize>>, Error> {
|
||||
let result = match self.state_stack.pop() {
|
||||
Some(State::ObjectStart) => {
|
||||
try!(self.parse_object_start())
|
||||
@ -631,7 +631,7 @@ impl<Iter: Iterator<Item=u8>> de::Deserializer<Error> for Parser<Iter> {
|
||||
None => { return Ok(None); }
|
||||
};
|
||||
|
||||
Ok(Some(fields.iter().position(|field| *field == s.as_slice())))
|
||||
Ok(Some(fields.iter().position(|field| *field == &s[])))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
use std::old_io;
|
||||
|
||||
use de::{Token, TokenKind};
|
||||
|
||||
@ -40,7 +40,7 @@ pub enum ErrorCode {
|
||||
UnrecognizedHex,
|
||||
}
|
||||
|
||||
impl fmt::Show for ErrorCode {
|
||||
impl fmt::Debug for ErrorCode {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
ErrorCode::ConversionError(ref token) => write!(f, "failed to convert {:?}", token),
|
||||
@ -78,11 +78,11 @@ impl fmt::Show for ErrorCode {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Show)]
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub enum Error {
|
||||
/// msg, line, col
|
||||
SyntaxError(ErrorCode, uint, uint),
|
||||
IoError(io::IoError),
|
||||
SyntaxError(ErrorCode, usize, usize),
|
||||
IoError(old_io::IoError),
|
||||
ExpectedError(String, String),
|
||||
MissingFieldError(String),
|
||||
UnknownVariantError(String),
|
||||
@ -92,34 +92,36 @@ impl error::Error for Error {
|
||||
fn description(&self) -> &str {
|
||||
match *self {
|
||||
Error::SyntaxError(..) => "syntax error",
|
||||
Error::IoError(ref error) => error.description(),
|
||||
Error::ExpectedError(ref expected, _) => expected.as_slice(),
|
||||
Error::IoError(_) => "Input/Output error",
|
||||
Error::ExpectedError(ref expected, _) => &expected,
|
||||
Error::MissingFieldError(_) => "missing field",
|
||||
Error::UnknownVariantError(_) => "unknown variant",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn detail(&self) -> Option<String> {
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Error::SyntaxError(ref code, line, col) => {
|
||||
Some(format!("{:?} at line {:?} column {:?}", code, line, col))
|
||||
write!(fmt, "{:?} at line {:?} column {:?}", code, line, col)
|
||||
}
|
||||
Error::IoError(ref error) => error.detail(),
|
||||
Error::IoError(ref error) => fmt::Display::fmt(error, fmt),
|
||||
Error::ExpectedError(ref expected, ref found) => {
|
||||
Some(format!("expected {:?}, found {:?}", expected, found))
|
||||
write!(fmt, "expected {:?}, found {:?}", expected, found)
|
||||
}
|
||||
Error::MissingFieldError(ref field) => {
|
||||
Some(format!("missing field {:?}", field))
|
||||
write!(fmt, "missing field {:?}", field)
|
||||
}
|
||||
Error::UnknownVariantError(ref variant) => {
|
||||
Some(format!("unknown variant {:?}", variant))
|
||||
write!(fmt, "unknown variant {:?}", variant)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl error::FromError<io::IoError> for Error {
|
||||
fn from_error(error: io::IoError) -> Error {
|
||||
impl error::FromError<old_io::IoError> for Error {
|
||||
fn from_error(error: old_io::IoError) -> Error {
|
||||
Error::IoError(error)
|
||||
}
|
||||
}
|
||||
|
142
src/json/mod.rs
142
src/json/mod.rs
@ -65,7 +65,7 @@ To serialize using `Serialize`:
|
||||
extern crate serde_macros;
|
||||
extern crate serde;
|
||||
|
||||
use std::io::ByRefWriter;
|
||||
use std::old_io::ByRefWriter;
|
||||
use serde::json;
|
||||
use serde::Serialize;
|
||||
|
||||
@ -232,7 +232,7 @@ fn main() {
|
||||
|
||||
// To deserialize use the `json::from_str` function.
|
||||
|
||||
let deserialized_object: TestStruct1 = match json::from_str(serialized_str.as_slice()) {
|
||||
let deserialized_object: TestStruct1 = match json::from_str(&serialized_str) {
|
||||
Ok(deserialized_object) => deserialized_object,
|
||||
Err(e) => panic!("json deserialization error: {:?}", e),
|
||||
};
|
||||
@ -285,7 +285,7 @@ fn main() {
|
||||
|
||||
// Deserialize like before.
|
||||
|
||||
let mut parser = json::Parser::new(json_str.as_slice().bytes());
|
||||
let mut parser = json::Parser::new(json_str.bytes());
|
||||
let deserialized: TestStruct1 = Deserialize::deserialize(&mut parser).unwrap();
|
||||
}
|
||||
```
|
||||
@ -318,8 +318,8 @@ pub mod error;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::fmt::Show;
|
||||
use std::io;
|
||||
use std::fmt::Debug;
|
||||
use std::old_io;
|
||||
use std::str;
|
||||
use std::string;
|
||||
use std::collections::BTreeMap;
|
||||
@ -357,12 +357,12 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Show)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive_serialize]
|
||||
#[derive_deserialize]
|
||||
enum Animal {
|
||||
Dog,
|
||||
Frog(String, Vec<int>)
|
||||
Frog(String, Vec<isize>)
|
||||
}
|
||||
|
||||
impl ToJson for Animal {
|
||||
@ -386,12 +386,12 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Show)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive_serialize]
|
||||
#[derive_deserialize]
|
||||
struct Inner {
|
||||
a: (),
|
||||
b: uint,
|
||||
b: usize,
|
||||
c: Vec<string::String>,
|
||||
}
|
||||
|
||||
@ -407,7 +407,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Show)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive_serialize]
|
||||
#[derive_deserialize]
|
||||
struct Outer {
|
||||
@ -425,9 +425,9 @@ mod tests {
|
||||
}
|
||||
|
||||
fn test_encode_ok<
|
||||
T: PartialEq + Show + ToJson + ser::Serialize<super::Serializer<Vec<u8>>, io::IoError>
|
||||
T: PartialEq + Debug + ToJson + ser::Serialize<super::Serializer<Vec<u8>>, old_io::IoError>
|
||||
>(errors: &[(T, &str)]) {
|
||||
for &(ref value, out) in errors.iter() {
|
||||
for &(ref value, out) in errors {
|
||||
let out = out.to_string();
|
||||
|
||||
let s = super::to_string(value).unwrap();
|
||||
@ -439,9 +439,9 @@ mod tests {
|
||||
}
|
||||
|
||||
fn test_pretty_encode_ok<
|
||||
T: PartialEq + Show + ToJson + ser::Serialize<super::PrettySerializer<Vec<u8>>, io::IoError>
|
||||
T: PartialEq + Debug + ToJson + ser::Serialize<super::PrettySerializer<Vec<u8>>, old_io::IoError>
|
||||
>(errors: &[(T, &str)]) {
|
||||
for &(ref value, out) in errors.iter() {
|
||||
for &(ref value, out) in errors {
|
||||
let out = out.to_string();
|
||||
|
||||
let s = super::to_pretty_string(value).unwrap();
|
||||
@ -464,9 +464,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_write_i64() {
|
||||
let tests = &[
|
||||
(3i, "3"),
|
||||
(-2i, "-2"),
|
||||
(-1234i, "-1234"),
|
||||
(3is, "3"),
|
||||
(-2is, "-2"),
|
||||
(-1234is, "-1234"),
|
||||
];
|
||||
test_encode_ok(tests);
|
||||
test_pretty_encode_ok(tests);
|
||||
@ -643,14 +643,14 @@ mod tests {
|
||||
fn test_write_tuple() {
|
||||
test_encode_ok(&[
|
||||
(
|
||||
(5i,),
|
||||
(5is,),
|
||||
"[5]",
|
||||
),
|
||||
]);
|
||||
|
||||
test_pretty_encode_ok(&[
|
||||
(
|
||||
(5i,),
|
||||
(5is,),
|
||||
concat!(
|
||||
"[\n",
|
||||
" 5\n",
|
||||
@ -661,14 +661,14 @@ mod tests {
|
||||
|
||||
test_encode_ok(&[
|
||||
(
|
||||
(5i, (6i, "abc")),
|
||||
(5is, (6is, "abc")),
|
||||
"[5,[6,\"abc\"]]",
|
||||
),
|
||||
]);
|
||||
|
||||
test_pretty_encode_ok(&[
|
||||
(
|
||||
(5i, (6i, "abc")),
|
||||
(5is, (6is, "abc")),
|
||||
concat!(
|
||||
"[\n",
|
||||
" 5,\n",
|
||||
@ -776,9 +776,9 @@ mod tests {
|
||||
// FIXME (#5527): these could be merged once UFCS is finished.
|
||||
fn test_parse_err<
|
||||
'a,
|
||||
T: Show + de::Deserialize<Parser<str::Bytes<'a>>, Error>
|
||||
T: Debug + de::Deserialize<Parser<str::Bytes<'a>>, Error>
|
||||
>(errors: &[(&'a str, Error)]) {
|
||||
for &(s, ref err) in errors.iter() {
|
||||
for &(s, ref err) in errors {
|
||||
let v: Result<T, Error> = from_str(s);
|
||||
assert_eq!(v.unwrap_err(), *err);
|
||||
}
|
||||
@ -786,9 +786,9 @@ mod tests {
|
||||
|
||||
fn test_parse_ok<
|
||||
'a,
|
||||
T: PartialEq + Show + ToJson + de::Deserialize<Parser<str::Bytes<'a>>, Error>
|
||||
T: PartialEq + Debug + ToJson + de::Deserialize<Parser<str::Bytes<'a>>, Error>
|
||||
>(errors: &[(&'a str, T)]) {
|
||||
for &(s, ref value) in errors.iter() {
|
||||
for &(s, ref value) in errors {
|
||||
let v: T = from_str(s).unwrap();
|
||||
assert_eq!(v, *value);
|
||||
|
||||
@ -798,9 +798,9 @@ mod tests {
|
||||
}
|
||||
|
||||
fn test_json_deserialize_ok<
|
||||
T: PartialEq + Show + ToJson + de::Deserialize<value::Deserializer, Error>
|
||||
T: PartialEq + Debug + ToJson + de::Deserialize<value::Deserializer, Error>
|
||||
>(errors: &[T]) {
|
||||
for value in errors.iter() {
|
||||
for value in errors {
|
||||
let v: T = from_json(value.to_json()).unwrap();
|
||||
assert_eq!(v, *value);
|
||||
|
||||
@ -964,19 +964,19 @@ mod tests {
|
||||
]);
|
||||
|
||||
test_parse_ok(&[
|
||||
("[3,1]", vec!(3i, 1)),
|
||||
("[ 3 , 1 ]", vec!(3i, 1)),
|
||||
("[3,1]", vec!(3is, 1)),
|
||||
("[ 3 , 1 ]", vec!(3is, 1)),
|
||||
]);
|
||||
|
||||
test_parse_ok(&[
|
||||
("[[3], [1, 2]]", vec!(vec!(3i), vec!(1, 2))),
|
||||
("[[3], [1, 2]]", vec!(vec!(3is), vec!(1, 2))),
|
||||
]);
|
||||
|
||||
let v: () = from_str("[]").unwrap();
|
||||
assert_eq!(v, ());
|
||||
|
||||
test_parse_ok(&[
|
||||
("[1, 2, 3]", (1u, 2u, 3u)),
|
||||
("[1, 2, 3]", (1us, 2us, 3us)),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -992,17 +992,17 @@ mod tests {
|
||||
]);
|
||||
|
||||
test_json_deserialize_ok(&[
|
||||
vec!(3i, 1),
|
||||
vec!(3is, 1),
|
||||
]);
|
||||
|
||||
test_json_deserialize_ok(&[
|
||||
vec!(vec!(3i), vec!(1, 2)),
|
||||
vec!(vec!(3is), vec!(1, 2)),
|
||||
]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_object() {
|
||||
test_parse_err::<BTreeMap<string::String, int>>(&[
|
||||
test_parse_err::<BTreeMap<string::String, isize>>(&[
|
||||
("{", SyntaxError(EOFWhileParsingString, 1, 2)),
|
||||
("{ ", SyntaxError(EOFWhileParsingString, 1, 3)),
|
||||
("{1", SyntaxError(KeyMustBeAString, 1, 2)),
|
||||
@ -1022,26 +1022,26 @@ mod tests {
|
||||
("{ }", treemap!()),
|
||||
(
|
||||
"{\"a\":3}",
|
||||
treemap!("a".to_string() => 3i)
|
||||
treemap!("a".to_string() => 3is)
|
||||
),
|
||||
(
|
||||
"{ \"a\" : 3 }",
|
||||
treemap!("a".to_string() => 3i)
|
||||
treemap!("a".to_string() => 3is)
|
||||
),
|
||||
(
|
||||
"{\"a\":3,\"b\":4}",
|
||||
treemap!("a".to_string() => 3i, "b".to_string() => 4)
|
||||
treemap!("a".to_string() => 3is, "b".to_string() => 4)
|
||||
),
|
||||
(
|
||||
"{ \"a\" : 3 , \"b\" : 4 }",
|
||||
treemap!("a".to_string() => 3i, "b".to_string() => 4),
|
||||
treemap!("a".to_string() => 3is, "b".to_string() => 4),
|
||||
),
|
||||
]);
|
||||
|
||||
test_parse_ok(&[
|
||||
(
|
||||
"{\"a\": {\"b\": 3, \"c\": 4}}",
|
||||
treemap!("a".to_string() => treemap!("b".to_string() => 3i, "c".to_string() => 4i)),
|
||||
treemap!("a".to_string() => treemap!("b".to_string() => 3is, "c".to_string() => 4is)),
|
||||
),
|
||||
]);
|
||||
}
|
||||
@ -1050,12 +1050,12 @@ mod tests {
|
||||
fn test_json_deserialize_object() {
|
||||
test_json_deserialize_ok(&[
|
||||
treemap!(),
|
||||
treemap!("a".to_string() => 3i),
|
||||
treemap!("a".to_string() => 3i, "b".to_string() => 4),
|
||||
treemap!("a".to_string() => 3is),
|
||||
treemap!("a".to_string() => 3is, "b".to_string() => 4),
|
||||
]);
|
||||
|
||||
test_json_deserialize_ok(&[
|
||||
treemap!("a".to_string() => treemap!("b".to_string() => 3i, "c".to_string() => 4)),
|
||||
treemap!("a".to_string() => treemap!("b".to_string() => 3is, "c".to_string() => 4)),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -1103,11 +1103,11 @@ mod tests {
|
||||
("\"jodhpurs\"", Some("jodhpurs".to_string())),
|
||||
]);
|
||||
|
||||
#[derive(PartialEq, Show)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive_serialize]
|
||||
#[derive_deserialize]
|
||||
struct Foo {
|
||||
x: Option<int>,
|
||||
x: Option<isize>,
|
||||
}
|
||||
|
||||
let value: Foo = from_str("{}").unwrap();
|
||||
@ -1172,7 +1172,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_multiline_errors() {
|
||||
test_parse_err::<BTreeMap<string::String, string::String>>(&[
|
||||
("{\n \"foo\":\n \"bar\"", SyntaxError(EOFWhileParsingObject, 3u, 8u)),
|
||||
("{\n \"foo\":\n \"bar\"", SyntaxError(EOFWhileParsingObject, 3us, 8us)),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -1266,8 +1266,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_as_object() {
|
||||
let json_value: Value = from_str("{}").unwrap();
|
||||
let json_object = json_value.as_object();
|
||||
let map = BTreeMap::<string::String, Value>::new();
|
||||
let json_object = json_value.as_object();
|
||||
assert_eq!(json_object, Some(&map));
|
||||
}
|
||||
|
||||
@ -1371,7 +1371,7 @@ mod tests {
|
||||
fn test_encode_hashmap_with_numeric_key() {
|
||||
use std::str::from_utf8;
|
||||
use std::collections::HashMap;
|
||||
let mut hm: HashMap<uint, bool> = HashMap::new();
|
||||
let mut hm: HashMap<usize, bool> = HashMap::new();
|
||||
hm.insert(1, true);
|
||||
let mut mem_buf = MemWriter::new();
|
||||
{
|
||||
@ -1379,14 +1379,14 @@ mod tests {
|
||||
hm.serialize(&mut serializer).unwrap();
|
||||
}
|
||||
let bytes = mem_buf.unwrap();
|
||||
let json_str = from_utf8(bytes.as_slice()).unwrap();
|
||||
let json_str = from_utf8(&bytes).unwrap();
|
||||
let _json_value: Value = from_str(json_str).unwrap();
|
||||
}
|
||||
#[test]
|
||||
fn test_prettyencode_hashmap_with_numeric_key() {
|
||||
use std::str::from_utf8;
|
||||
use std::collections::HashMap;
|
||||
let mut hm: HashMap<uint, bool> = HashMap::new();
|
||||
let mut hm: HashMap<usize, bool> = HashMap::new();
|
||||
hm.insert(1, true);
|
||||
let mut mem_buf = MemWriter::new();
|
||||
{
|
||||
@ -1394,7 +1394,7 @@ mod tests {
|
||||
hm.serialize(&mut serializer).unwrap()
|
||||
}
|
||||
let bytes = mem_buf.unwrap();
|
||||
let json_str = from_utf8(bytes.as_slice()).unwrap();
|
||||
let json_str = from_utf8(&bytes).unwrap();
|
||||
let _json_value: Value = from_str(json_str).unwrap();
|
||||
}
|
||||
|
||||
@ -1402,7 +1402,7 @@ mod tests {
|
||||
fn test_hashmap_with_numeric_key_can_handle_double_quote_delimited_key() {
|
||||
use std::collections::HashMap;
|
||||
let json_str = "{\"1\":true}";
|
||||
let map: HashMap<uint, bool> = from_str(json_str).unwrap();
|
||||
let map: HashMap<usize, bool> = from_str(json_str).unwrap();
|
||||
let mut m = HashMap::new();
|
||||
m.insert(1u, true);
|
||||
assert_eq!(map, m);
|
||||
@ -1419,7 +1419,7 @@ mod tests {
|
||||
None => { break; }
|
||||
};
|
||||
let (ref expected_evt, ref expected_stack) = expected[i];
|
||||
if !parser.stack().is_equal_to(expected_stack.as_slice()) {
|
||||
if !parser.stack().is_equal_to(&expected_stack) {
|
||||
panic!("Parser stack is not equal to {}", expected_stack);
|
||||
}
|
||||
assert_eq!(&evt, expected_evt);
|
||||
@ -1700,7 +1700,7 @@ mod tests {
|
||||
mod bench {
|
||||
use std::collections::BTreeMap;
|
||||
use std::string;
|
||||
use serialize;
|
||||
use rustc_serialize as serialize;
|
||||
use test::Bencher;
|
||||
|
||||
use de::Token;
|
||||
@ -1715,7 +1715,7 @@ mod bench {
|
||||
})
|
||||
}
|
||||
|
||||
fn json_str(count: uint) -> string::String {
|
||||
fn json_str(count: usize) -> string::String {
|
||||
let mut src = "[".to_string();
|
||||
for _ in range(0, count) {
|
||||
src.push_str(r#"{"a":true,"b":null,"c":3.1415,"d":"Hello world","e":[1,2,3]},"#);
|
||||
@ -1724,7 +1724,7 @@ mod bench {
|
||||
src
|
||||
}
|
||||
|
||||
fn pretty_json_str(count: uint) -> string::String {
|
||||
fn pretty_json_str(count: usize) -> string::String {
|
||||
let mut src = "[\n".to_string();
|
||||
for _ in range(0, count) {
|
||||
src.push_str(
|
||||
@ -1747,8 +1747,8 @@ mod bench {
|
||||
src
|
||||
}
|
||||
|
||||
fn encoder_json(count: uint) -> serialize::json::Json {
|
||||
use serialize::json::Json;
|
||||
fn encoder_json(count: usize) -> serialize::json::Json {
|
||||
use rustc_serialize::json::Json;
|
||||
|
||||
let mut list = vec!();
|
||||
for _ in range(0, count) {
|
||||
@ -1768,7 +1768,7 @@ mod bench {
|
||||
Json::Array(list)
|
||||
}
|
||||
|
||||
fn serializer_json(count: uint) -> Value {
|
||||
fn serializer_json(count: usize) -> Value {
|
||||
let mut list = vec!();
|
||||
for _ in range(0, count) {
|
||||
list.push(Value::Object(treemap!(
|
||||
@ -1787,7 +1787,7 @@ mod bench {
|
||||
Value::Array(list)
|
||||
}
|
||||
|
||||
fn bench_encoder(b: &mut Bencher, count: uint) {
|
||||
fn bench_encoder(b: &mut Bencher, count: usize) {
|
||||
let src = json_str(count);
|
||||
let json = encoder_json(count);
|
||||
|
||||
@ -1796,7 +1796,7 @@ mod bench {
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_encoder_pretty(b: &mut Bencher, count: uint) {
|
||||
fn bench_encoder_pretty(b: &mut Bencher, count: usize) {
|
||||
let src = pretty_json_str(count);
|
||||
let json = encoder_json(count);
|
||||
|
||||
@ -1805,7 +1805,7 @@ mod bench {
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_serializer(b: &mut Bencher, count: uint) {
|
||||
fn bench_serializer(b: &mut Bencher, count: usize) {
|
||||
let src = json_str(count);
|
||||
let json = serializer_json(count);
|
||||
|
||||
@ -1814,7 +1814,7 @@ mod bench {
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_serializer_pretty(b: &mut Bencher, count: uint) {
|
||||
fn bench_serializer_pretty(b: &mut Bencher, count: usize) {
|
||||
let src = pretty_json_str(count);
|
||||
let json = serializer_json(count);
|
||||
|
||||
@ -1823,29 +1823,29 @@ mod bench {
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_decoder(b: &mut Bencher, count: uint) {
|
||||
fn bench_decoder(b: &mut Bencher, count: usize) {
|
||||
let src = json_str(count);
|
||||
let json = encoder_json(count);
|
||||
b.iter(|| {
|
||||
assert_eq!(json, serialize::json::from_str(src.as_slice()).unwrap());
|
||||
assert_eq!(json, serialize::json::Json::from_str(&src).unwrap());
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_deserializer(b: &mut Bencher, count: uint) {
|
||||
fn bench_deserializer(b: &mut Bencher, count: usize) {
|
||||
let src = json_str(count);
|
||||
let json = encoder_json(count);
|
||||
b.iter(|| {
|
||||
assert_eq!(json, serialize::json::from_str(src.as_slice()).unwrap());
|
||||
assert_eq!(json, serialize::json::Json::from_str(&src).unwrap());
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_decoder_streaming(b: &mut Bencher, count: uint) {
|
||||
fn bench_decoder_streaming(b: &mut Bencher, count: usize) {
|
||||
let src = json_str(count);
|
||||
|
||||
b.iter( || {
|
||||
use serialize::json::{Parser, JsonEvent, StackElement};
|
||||
use rustc_serialize::json::{Parser, JsonEvent, StackElement};
|
||||
|
||||
let mut parser = Parser::new(src.as_slice().chars());
|
||||
let mut parser = Parser::new(src.chars());
|
||||
assert_eq!(parser.next(), Some(JsonEvent::ArrayStart));
|
||||
for _ in range(0, count) {
|
||||
assert_eq!(parser.next(), Some(JsonEvent::ObjectStart));
|
||||
@ -1878,11 +1878,11 @@ mod bench {
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_deserializer_streaming(b: &mut Bencher, count: uint) {
|
||||
fn bench_deserializer_streaming(b: &mut Bencher, count: usize) {
|
||||
let src = json_str(count);
|
||||
|
||||
b.iter( || {
|
||||
let mut parser = Parser::new(src.as_slice().bytes());
|
||||
let mut parser = Parser::new(src.bytes());
|
||||
|
||||
assert_eq!(parser.next(), Some(Ok(Token::SeqStart(0))));
|
||||
for _ in range(0, count) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::f32;
|
||||
use std::f64;
|
||||
use std::num::{Float, FpCategory};
|
||||
use std::io::{IoError, IoResult};
|
||||
use std::old_io::{IoError, IoResult};
|
||||
use std::string::FromUtf8Error;
|
||||
|
||||
use ser::Serialize;
|
||||
@ -25,7 +25,7 @@ fn escape_bytes<W: Writer>(wr: &mut W, bytes: &[u8]) -> IoResult<()> {
|
||||
};
|
||||
|
||||
if start < i {
|
||||
try!(wr.write(bytes.slice(start, i)));
|
||||
try!(wr.write_all(&bytes[start..i]));
|
||||
}
|
||||
|
||||
try!(wr.write_str(escaped));
|
||||
@ -34,7 +34,7 @@ fn escape_bytes<W: Writer>(wr: &mut W, bytes: &[u8]) -> IoResult<()> {
|
||||
}
|
||||
|
||||
if start != bytes.len() {
|
||||
try!(wr.write(bytes.slice_from(start)));
|
||||
try!(wr.write_all(&bytes[start..]));
|
||||
}
|
||||
|
||||
wr.write_str("\"")
|
||||
@ -53,35 +53,35 @@ fn escape_char<W: Writer>(wr: &mut W, v: char) -> IoResult<()> {
|
||||
fn fmt_f32_or_null<W: Writer>(wr: &mut W, v: f32) -> IoResult<()> {
|
||||
match v.classify() {
|
||||
FpCategory::Nan | FpCategory::Infinite => wr.write_str("null"),
|
||||
_ => wr.write_str(f32::to_str_digits(v, 6).as_slice()),
|
||||
_ => wr.write_str(&f32::to_str_digits(v, 6)),
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt_f64_or_null<W: Writer>(wr: &mut W, v: f64) -> IoResult<()> {
|
||||
match v.classify() {
|
||||
FpCategory::Nan | FpCategory::Infinite => wr.write_str("null"),
|
||||
_ => wr.write_str(f64::to_str_digits(v, 6).as_slice()),
|
||||
_ => wr.write_str(&f64::to_str_digits(v, 6)),
|
||||
}
|
||||
}
|
||||
|
||||
fn spaces<W: Writer>(wr: &mut W, mut n: uint) -> IoResult<()> {
|
||||
const LEN: uint = 16;
|
||||
fn spaces<W: Writer>(wr: &mut W, mut n: usize) -> IoResult<()> {
|
||||
const LEN: usize = 16;
|
||||
const BUF: &'static [u8; LEN] = &[b' '; LEN];
|
||||
|
||||
while n >= LEN {
|
||||
try!(wr.write(BUF));
|
||||
try!(wr.write_all(BUF));
|
||||
n -= LEN;
|
||||
}
|
||||
|
||||
if n > 0 {
|
||||
wr.write(BUF.slice_to(n))
|
||||
wr.write_all(&BUF[..n])
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#[derive(Show)]
|
||||
#[derive(Debug)]
|
||||
enum SerializerState {
|
||||
ValueState,
|
||||
TupleState,
|
||||
@ -128,7 +128,7 @@ impl<W: Writer> ser::Serializer<IoError> for Serializer<W> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_int(&mut self, v: int) -> IoResult<()> {
|
||||
fn serialize_isize(&mut self, v: isize) -> IoResult<()> {
|
||||
write!(&mut self.wr, "{}", v)
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ impl<W: Writer> ser::Serializer<IoError> for Serializer<W> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_uint(&mut self, v: uint) -> IoResult<()> {
|
||||
fn serialize_usize(&mut self, v: usize) -> IoResult<()> {
|
||||
write!(&mut self.wr, "{}", v)
|
||||
}
|
||||
|
||||
@ -198,7 +198,7 @@ impl<W: Writer> ser::Serializer<IoError> for Serializer<W> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_tuple_start(&mut self, _len: uint) -> IoResult<()> {
|
||||
fn serialize_tuple_start(&mut self, _len: usize) -> IoResult<()> {
|
||||
self.first = true;
|
||||
self.wr.write_str("[")
|
||||
}
|
||||
@ -221,7 +221,7 @@ impl<W: Writer> ser::Serializer<IoError> for Serializer<W> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_struct_start(&mut self, _name: &str, _len: uint) -> IoResult<()> {
|
||||
fn serialize_struct_start(&mut self, _name: &str, _len: usize) -> IoResult<()> {
|
||||
self.first = true;
|
||||
self.wr.write_str("{")
|
||||
}
|
||||
@ -246,7 +246,7 @@ impl<W: Writer> ser::Serializer<IoError> for Serializer<W> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_enum_start(&mut self, _name: &str, variant: &str, _len: uint) -> IoResult<()> {
|
||||
fn serialize_enum_start(&mut self, _name: &str, variant: &str, _len: usize) -> IoResult<()> {
|
||||
self.first = true;
|
||||
try!(self.wr.write_str("{"));
|
||||
try!(self.serialize_str(variant));
|
||||
@ -288,7 +288,7 @@ impl<W: Writer> ser::Serializer<IoError> for Serializer<W> {
|
||||
fn serialize_seq<
|
||||
T: Serialize<Serializer<W>, IoError>,
|
||||
Iter: Iterator<Item=T>
|
||||
>(&mut self, mut iter: Iter) -> IoResult<()> {
|
||||
>(&mut self, iter: Iter) -> IoResult<()> {
|
||||
try!(self.wr.write_str("["));
|
||||
let mut first = true;
|
||||
for elt in iter {
|
||||
@ -308,7 +308,7 @@ impl<W: Writer> ser::Serializer<IoError> for Serializer<W> {
|
||||
K: Serialize<Serializer<W>, IoError>,
|
||||
V: Serialize<Serializer<W>, IoError>,
|
||||
Iter: Iterator<Item=(K, V)>
|
||||
>(&mut self, mut iter: Iter) -> IoResult<()> {
|
||||
>(&mut self, iter: Iter) -> IoResult<()> {
|
||||
try!(self.wr.write_str("{"));
|
||||
let mut first = true;
|
||||
for (key, value) in iter {
|
||||
@ -329,7 +329,7 @@ impl<W: Writer> ser::Serializer<IoError> for Serializer<W> {
|
||||
/// compact data
|
||||
pub struct PrettySerializer<W> {
|
||||
wr: W,
|
||||
indent: uint,
|
||||
indent: usize,
|
||||
first: bool,
|
||||
}
|
||||
|
||||
@ -391,7 +391,7 @@ impl<W: Writer> ser::Serializer<IoError> for PrettySerializer<W> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_int(&mut self, v: int) -> IoResult<()> {
|
||||
fn serialize_isize(&mut self, v: isize) -> IoResult<()> {
|
||||
write!(&mut self.wr, "{}", v)
|
||||
}
|
||||
|
||||
@ -416,7 +416,7 @@ impl<W: Writer> ser::Serializer<IoError> for PrettySerializer<W> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_uint(&mut self, v: uint) -> IoResult<()> {
|
||||
fn serialize_usize(&mut self, v: usize) -> IoResult<()> {
|
||||
write!(&mut self.wr, "{}", v)
|
||||
}
|
||||
|
||||
@ -461,7 +461,7 @@ impl<W: Writer> ser::Serializer<IoError> for PrettySerializer<W> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_tuple_start(&mut self, _len: uint) -> IoResult<()> {
|
||||
fn serialize_tuple_start(&mut self, _len: usize) -> IoResult<()> {
|
||||
self.first = true;
|
||||
self.wr.write_str("[")
|
||||
}
|
||||
@ -480,7 +480,7 @@ impl<W: Writer> ser::Serializer<IoError> for PrettySerializer<W> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_struct_start(&mut self, _name: &str, _len: uint) -> IoResult<()> {
|
||||
fn serialize_struct_start(&mut self, _name: &str, _len: usize) -> IoResult<()> {
|
||||
self.first = true;
|
||||
self.wr.write_str("{")
|
||||
}
|
||||
@ -501,7 +501,7 @@ impl<W: Writer> ser::Serializer<IoError> for PrettySerializer<W> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_enum_start(&mut self, _name: &str, variant: &str, _len: uint) -> IoResult<()> {
|
||||
fn serialize_enum_start(&mut self, _name: &str, variant: &str, _len: usize) -> IoResult<()> {
|
||||
self.first = true;
|
||||
try!(self.wr.write_str("{"));
|
||||
try!(self.serialize_sep());
|
||||
@ -542,7 +542,7 @@ impl<W: Writer> ser::Serializer<IoError> for PrettySerializer<W> {
|
||||
fn serialize_seq<
|
||||
T: Serialize<PrettySerializer<W>, IoError>,
|
||||
Iter: Iterator<Item=T>
|
||||
>(&mut self, mut iter: Iter) -> IoResult<()> {
|
||||
>(&mut self, iter: Iter) -> IoResult<()> {
|
||||
try!(self.wr.write_str("["));
|
||||
|
||||
self.first = true;
|
||||
@ -559,7 +559,7 @@ impl<W: Writer> ser::Serializer<IoError> for PrettySerializer<W> {
|
||||
K: Serialize<PrettySerializer<W>, IoError>,
|
||||
V: Serialize<PrettySerializer<W>, IoError>,
|
||||
Iter: Iterator<Item=(K, V)>
|
||||
>(&mut self, mut iter: Iter) -> IoResult<()> {
|
||||
>(&mut self, iter: Iter) -> IoResult<()> {
|
||||
try!(self.wr.write_str("{"));
|
||||
|
||||
self.first = true;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::collections::{HashMap, BTreeMap, btree_map};
|
||||
use std::fmt;
|
||||
use std::io::{ByRefWriter, IoResult};
|
||||
use std::io;
|
||||
use std::old_io::{ByRefWriter, IoResult};
|
||||
use std::old_io;
|
||||
use std::str;
|
||||
use std::string::ToString;
|
||||
use std::vec;
|
||||
@ -43,7 +43,7 @@ impl Value {
|
||||
pub fn to_pretty_string(&self) -> String {
|
||||
let mut wr = Vec::new();
|
||||
self.to_pretty_writer(wr.by_ref()).unwrap();
|
||||
str::from_utf8(wr.as_slice()).unwrap().to_string()
|
||||
str::from_utf8(&wr).unwrap().to_string()
|
||||
}
|
||||
|
||||
/// If the Json value is an Object, returns the value associated with the provided key.
|
||||
@ -60,7 +60,7 @@ impl Value {
|
||||
/// Otherwise, it will return the Json value associated with the final key.
|
||||
pub fn find_path<'a>(&'a self, keys: &[&String]) -> Option<&'a Value>{
|
||||
let mut target = self;
|
||||
for key in keys.iter() {
|
||||
for key in keys {
|
||||
match target.find(*key) {
|
||||
Some(t) => { target = t; },
|
||||
None => return None
|
||||
@ -79,7 +79,7 @@ impl Value {
|
||||
Some(json_value) => Some(json_value),
|
||||
None => {
|
||||
let mut value : Option<&'a Value> = None;
|
||||
for (_, v) in map.iter() {
|
||||
for (_, v) in map {
|
||||
value = v.search(key);
|
||||
if value.is_some() {
|
||||
break;
|
||||
@ -130,7 +130,7 @@ impl Value {
|
||||
/// Returns None otherwise.
|
||||
pub fn as_string<'a>(&'a self) -> Option<&'a str> {
|
||||
match *self {
|
||||
Value::String(ref s) => Some(s.as_slice()),
|
||||
Value::String(ref s) => Some(&s),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
@ -212,7 +212,7 @@ impl ToString for Value {
|
||||
fn to_string(&self) -> String {
|
||||
let mut wr = Vec::new();
|
||||
self.to_writer(wr.by_ref()).unwrap();
|
||||
str::from_utf8(wr.as_slice()).unwrap().to_string()
|
||||
str::from_utf8(&wr).unwrap().to_string()
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,12 +221,12 @@ struct WriterFormatter<'a, 'b: 'a> {
|
||||
}
|
||||
|
||||
impl<'a, 'b> Writer for WriterFormatter<'a, 'b> {
|
||||
fn write(&mut self, buf: &[u8]) -> IoResult<()> {
|
||||
self.inner.write_str(str::from_utf8(buf).unwrap()).map_err(|_| io::IoError::last_error())
|
||||
fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
|
||||
self.inner.write_str(str::from_utf8(buf).unwrap()).map_err(|_| old_io::IoError::last_error())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Show for Value {
|
||||
impl fmt::Debug for Value {
|
||||
/// Serializes a json value into a string
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let wr = WriterFormatter { inner: f };
|
||||
@ -269,12 +269,12 @@ impl<D: de::Deserializer<E>, E> de::Deserialize<D, E> for Value {
|
||||
match token {
|
||||
Token::Null => Ok(Value::Null),
|
||||
Token::Bool(x) => Ok(Value::Boolean(x)),
|
||||
Token::Int(x) => Ok(Value::Integer(x as i64)),
|
||||
Token::Isize(x) => Ok(Value::Integer(x as i64)),
|
||||
Token::I8(x) => Ok(Value::Integer(x as i64)),
|
||||
Token::I16(x) => Ok(Value::Integer(x as i64)),
|
||||
Token::I32(x) => Ok(Value::Integer(x as i64)),
|
||||
Token::I64(x) => Ok(Value::Integer(x)),
|
||||
Token::Uint(x) => Ok(Value::Integer(x as i64)),
|
||||
Token::Usize(x) => Ok(Value::Integer(x as i64)),
|
||||
Token::U8(x) => Ok(Value::Integer(x as i64)),
|
||||
Token::U16(x) => Ok(Value::Integer(x as i64)),
|
||||
Token::U32(x) => Ok(Value::Integer(x as i64)),
|
||||
@ -439,7 +439,7 @@ impl de::Deserializer<Error> for Deserializer {
|
||||
fn expect_enum_start(&mut self,
|
||||
token: Token,
|
||||
_name: &str,
|
||||
variants: &[&str]) -> Result<uint, Error> {
|
||||
variants: &[&str]) -> Result<usize, Error> {
|
||||
let variant = match token {
|
||||
Token::MapStart(_) => {
|
||||
let state = match self.stack.pop() {
|
||||
@ -498,7 +498,7 @@ impl de::Deserializer<Error> for Deserializer {
|
||||
}
|
||||
};
|
||||
|
||||
match variants.iter().position(|v| *v == variant.as_slice()) {
|
||||
match variants.iter().position(|v| *v == &variant[]) {
|
||||
Some(idx) => Ok(idx),
|
||||
None => Err(Error::UnknownVariantError(variant)),
|
||||
}
|
||||
@ -533,10 +533,10 @@ pub trait ToJson {
|
||||
}
|
||||
|
||||
impl ToJson for Value {
|
||||
fn to_json(&self) -> Value { (*self).clone() }
|
||||
fn to_json(&self) -> Value { self.clone() }
|
||||
}
|
||||
|
||||
impl ToJson for int {
|
||||
impl ToJson for isize {
|
||||
fn to_json(&self) -> Value { Value::Integer(*self as i64) }
|
||||
}
|
||||
|
||||
@ -556,7 +556,7 @@ impl ToJson for i64 {
|
||||
fn to_json(&self) -> Value { Value::Integer(*self as i64) }
|
||||
}
|
||||
|
||||
impl ToJson for uint {
|
||||
impl ToJson for usize {
|
||||
fn to_json(&self) -> Value { Value::Integer(*self as i64) }
|
||||
}
|
||||
|
||||
@ -593,7 +593,7 @@ impl<'a> ToJson for &'a str {
|
||||
}
|
||||
|
||||
impl ToJson for String {
|
||||
fn to_json(&self) -> Value { Value::String((*self).clone()) }
|
||||
fn to_json(&self) -> Value { Value::String(self.clone()) }
|
||||
}
|
||||
|
||||
macro_rules! peel_to_json_tuple {
|
||||
@ -643,8 +643,8 @@ impl<A:ToJson> ToJson for Vec<A> {
|
||||
impl<A:ToJson> ToJson for BTreeMap<String, A> {
|
||||
fn to_json(&self) -> Value {
|
||||
let mut d = BTreeMap::new();
|
||||
for (key, value) in self.iter() {
|
||||
d.insert((*key).clone(), value.to_json());
|
||||
for (key, value) in self {
|
||||
d.insert(key.clone(), value.to_json());
|
||||
}
|
||||
Value::Object(d)
|
||||
}
|
||||
@ -653,8 +653,8 @@ impl<A:ToJson> ToJson for BTreeMap<String, A> {
|
||||
impl<A:ToJson> ToJson for HashMap<String, A> {
|
||||
fn to_json(&self) -> Value {
|
||||
let mut d = BTreeMap::new();
|
||||
for (key, value) in self.iter() {
|
||||
d.insert((*key).clone(), value.to_json());
|
||||
for (key, value) in self {
|
||||
d.insert(key.clone(), value.to_json());
|
||||
}
|
||||
Value::Object(d)
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#![feature(plugin)]
|
||||
#![allow(unstable)]
|
||||
#![feature(plugin, io)]
|
||||
#![crate_type = "dylib"]
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
|
116
src/ser.rs
116
src/ser.rs
@ -22,7 +22,7 @@ pub trait Serializer<E> {
|
||||
fn serialize_bool(&mut self, v: bool) -> Result<(), E>;
|
||||
|
||||
#[inline]
|
||||
fn serialize_int(&mut self, v: int) -> Result<(), E> {
|
||||
fn serialize_isize(&mut self, v: isize) -> Result<(), E> {
|
||||
self.serialize_i64(v as i64)
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ pub trait Serializer<E> {
|
||||
fn serialize_i64(&mut self, v: i64) -> Result<(), E>;
|
||||
|
||||
#[inline]
|
||||
fn serialize_uint(&mut self, v: uint) -> Result<(), E> {
|
||||
fn serialize_usize(&mut self, v: usize) -> Result<(), E> {
|
||||
self.serialize_u64(v as u64)
|
||||
}
|
||||
|
||||
@ -78,19 +78,19 @@ pub trait Serializer<E> {
|
||||
|
||||
fn serialize_str(&mut self, v: &str) -> Result<(), E>;
|
||||
|
||||
fn serialize_tuple_start(&mut self, len: uint) -> Result<(), E>;
|
||||
fn serialize_tuple_start(&mut self, len: usize) -> Result<(), E>;
|
||||
fn serialize_tuple_elt<
|
||||
T: Serialize<Self, E>
|
||||
>(&mut self, v: &T) -> Result<(), E>;
|
||||
fn serialize_tuple_end(&mut self) -> Result<(), E>;
|
||||
|
||||
fn serialize_struct_start(&mut self, name: &str, len: uint) -> Result<(), E>;
|
||||
fn serialize_struct_start(&mut self, name: &str, len: usize) -> Result<(), E>;
|
||||
fn serialize_struct_elt<
|
||||
T: Serialize<Self, E>
|
||||
>(&mut self, name: &str, v: &T) -> Result<(), E>;
|
||||
fn serialize_struct_end(&mut self) -> Result<(), E>;
|
||||
|
||||
fn serialize_enum_start(&mut self, name: &str, variant: &str, len: uint) -> Result<(), E>;
|
||||
fn serialize_enum_start(&mut self, name: &str, variant: &str, len: usize) -> Result<(), E>;
|
||||
fn serialize_enum_elt<
|
||||
T: Serialize<Self, E>
|
||||
>(&mut self, v: &T) -> Result<(), E>;
|
||||
@ -132,12 +132,12 @@ macro_rules! impl_serialize {
|
||||
}
|
||||
|
||||
impl_serialize!(bool, serialize_bool);
|
||||
impl_serialize!(int, serialize_int);
|
||||
impl_serialize!(isize, serialize_isize);
|
||||
impl_serialize!(i8, serialize_i8);
|
||||
impl_serialize!(i16, serialize_i16);
|
||||
impl_serialize!(i32, serialize_i32);
|
||||
impl_serialize!(i64, serialize_i64);
|
||||
impl_serialize!(uint, serialize_uint);
|
||||
impl_serialize!(usize, serialize_usize);
|
||||
impl_serialize!(u8, serialize_u8);
|
||||
impl_serialize!(u16, serialize_u16);
|
||||
impl_serialize!(u32, serialize_u32);
|
||||
@ -158,7 +158,7 @@ impl<'a, S: Serializer<E>, E> Serialize<S, E> for &'a str {
|
||||
impl<S: Serializer<E>, E> Serialize<S, E> for String {
|
||||
#[inline]
|
||||
fn serialize(&self, s: &mut S) -> Result<(), E> {
|
||||
self.as_slice().serialize(s)
|
||||
(&self[]).serialize(s)
|
||||
}
|
||||
}
|
||||
|
||||
@ -328,17 +328,17 @@ mod tests {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Clone, PartialEq, Show, RustcDecodable)]
|
||||
#[derive(Clone, PartialEq, Debug, RustcDecodable)]
|
||||
#[derive_serialize]
|
||||
struct Inner {
|
||||
a: (),
|
||||
b: uint,
|
||||
b: usize,
|
||||
c: HashMap<string::String, option::Option<char>>,
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Clone, PartialEq, Show, RustcDecodable)]
|
||||
#[derive(Clone, PartialEq, Debug, RustcDecodable)]
|
||||
#[derive_serialize]
|
||||
struct Outer {
|
||||
inner: Vec<Inner>,
|
||||
@ -346,25 +346,25 @@ mod tests {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Clone, PartialEq, Show, RustcDecodable)]
|
||||
#[derive(Clone, PartialEq, Debug, RustcDecodable)]
|
||||
#[derive_serialize]
|
||||
enum Animal {
|
||||
Dog,
|
||||
Frog(String, int)
|
||||
Frog(String, isize)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Clone, PartialEq, Show)]
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub enum Token<'a> {
|
||||
Null,
|
||||
Bool(bool),
|
||||
Int(int),
|
||||
Isize(isize),
|
||||
I8(i8),
|
||||
I16(i16),
|
||||
I32(i32),
|
||||
I64(i64),
|
||||
Uint(uint),
|
||||
Usize(usize),
|
||||
U8(u8),
|
||||
U16(u16),
|
||||
U32(u32),
|
||||
@ -374,28 +374,28 @@ mod tests {
|
||||
Char(char),
|
||||
Str(&'a str),
|
||||
|
||||
TupleStart(uint),
|
||||
TupleStart(usize),
|
||||
TupleSep,
|
||||
TupleEnd,
|
||||
|
||||
StructStart(&'a str, uint),
|
||||
StructStart(&'a str, usize),
|
||||
StructSep(&'a str),
|
||||
StructEnd,
|
||||
|
||||
EnumStart(&'a str, &'a str, uint),
|
||||
EnumStart(&'a str, &'a str, usize),
|
||||
EnumSep,
|
||||
EnumEnd,
|
||||
|
||||
Option(bool),
|
||||
|
||||
SeqStart(uint),
|
||||
SeqStart(usize),
|
||||
SeqEnd,
|
||||
|
||||
MapStart(uint),
|
||||
MapStart(usize),
|
||||
MapEnd,
|
||||
}
|
||||
|
||||
#[derive(Show)]
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)]
|
||||
enum Error {
|
||||
EndOfStream,
|
||||
@ -434,8 +434,8 @@ mod tests {
|
||||
fn serialize_bool(&mut self, v: bool) -> Result<(), Error> {
|
||||
self.serialize(Token::Bool(v))
|
||||
}
|
||||
fn serialize_int(&mut self, v: int) -> Result<(), Error> {
|
||||
self.serialize(Token::Int(v))
|
||||
fn serialize_isize(&mut self, v: isize) -> Result<(), Error> {
|
||||
self.serialize(Token::Isize(v))
|
||||
}
|
||||
|
||||
fn serialize_i8(&mut self, v: i8) -> Result<(), Error> {
|
||||
@ -454,8 +454,8 @@ mod tests {
|
||||
self.serialize(Token::I64(v))
|
||||
}
|
||||
|
||||
fn serialize_uint(&mut self, v: uint) -> Result<(), Error> {
|
||||
self.serialize(Token::Uint(v))
|
||||
fn serialize_usize(&mut self, v: usize) -> Result<(), Error> {
|
||||
self.serialize(Token::Usize(v))
|
||||
}
|
||||
|
||||
fn serialize_u8(&mut self, v: u8) -> Result<(), Error> {
|
||||
@ -490,7 +490,7 @@ mod tests {
|
||||
self.serialize(Token::Str(v))
|
||||
}
|
||||
|
||||
fn serialize_tuple_start(&mut self, len: uint) -> Result<(), Error> {
|
||||
fn serialize_tuple_start(&mut self, len: usize) -> Result<(), Error> {
|
||||
self.serialize(Token::TupleStart(len))
|
||||
}
|
||||
|
||||
@ -505,7 +505,7 @@ mod tests {
|
||||
self.serialize(Token::TupleEnd)
|
||||
}
|
||||
|
||||
fn serialize_struct_start(&mut self, name: &str, len: uint) -> Result<(), Error> {
|
||||
fn serialize_struct_start(&mut self, name: &str, len: usize) -> Result<(), Error> {
|
||||
self.serialize(Token::StructStart(name, len))
|
||||
}
|
||||
|
||||
@ -520,7 +520,7 @@ mod tests {
|
||||
self.serialize(Token::StructEnd)
|
||||
}
|
||||
|
||||
fn serialize_enum_start(&mut self, name: &str, variant: &str, len: uint) -> Result<(), Error> {
|
||||
fn serialize_enum_start(&mut self, name: &str, variant: &str, len: usize) -> Result<(), Error> {
|
||||
self.serialize(Token::EnumStart(name, variant, len))
|
||||
}
|
||||
|
||||
@ -552,7 +552,7 @@ mod tests {
|
||||
fn serialize_seq<
|
||||
T: Serialize<AssertSerializer<Iter>, Error>,
|
||||
SeqIter: Iterator<Item=T>
|
||||
>(&mut self, mut iter: SeqIter) -> Result<(), Error> {
|
||||
>(&mut self, iter: SeqIter) -> Result<(), Error> {
|
||||
let (len, _) = iter.size_hint();
|
||||
try!(self.serialize(Token::SeqStart(len)));
|
||||
for elt in iter {
|
||||
@ -565,7 +565,7 @@ mod tests {
|
||||
K: Serialize<AssertSerializer<Iter>, Error>,
|
||||
V: Serialize<AssertSerializer<Iter>, Error>,
|
||||
MapIter: Iterator<Item=(K, V)>
|
||||
>(&mut self, mut iter: MapIter) -> Result<(), Error> {
|
||||
>(&mut self, iter: MapIter) -> Result<(), Error> {
|
||||
let (len, _) = iter.size_hint();
|
||||
try!(self.serialize(Token::MapStart(len)));
|
||||
for (key, value) in iter {
|
||||
@ -581,10 +581,10 @@ mod tests {
|
||||
#[test]
|
||||
fn test_tokens_int() {
|
||||
let tokens = vec!(
|
||||
Token::Int(5)
|
||||
Token::Isize(5)
|
||||
);
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
5i.serialize(&mut serializer).unwrap();
|
||||
5is.serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
|
||||
@ -617,7 +617,7 @@ mod tests {
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
None::<int>.serialize(&mut serializer).unwrap();
|
||||
None::<isize>.serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
|
||||
@ -625,11 +625,11 @@ mod tests {
|
||||
fn test_tokens_option_some() {
|
||||
let tokens = vec!(
|
||||
Token::Option(true),
|
||||
Token::Int(5),
|
||||
Token::Isize(5),
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
Some(5i).serialize(&mut serializer).unwrap();
|
||||
Some(5is).serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
|
||||
@ -638,7 +638,7 @@ mod tests {
|
||||
let tokens = vec!(
|
||||
Token::TupleStart(2),
|
||||
Token::TupleSep,
|
||||
Token::Int(5),
|
||||
Token::Isize(5),
|
||||
|
||||
Token::TupleSep,
|
||||
Token::Str("a"),
|
||||
@ -646,7 +646,7 @@ mod tests {
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
(5i, "a").serialize(&mut serializer).unwrap();
|
||||
(5is, "a").serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
|
||||
@ -663,7 +663,7 @@ mod tests {
|
||||
Token::TupleSep,
|
||||
Token::TupleStart(2),
|
||||
Token::TupleSep,
|
||||
Token::Int(5),
|
||||
Token::Isize(5),
|
||||
|
||||
Token::TupleSep,
|
||||
Token::Str("a"),
|
||||
@ -672,7 +672,7 @@ mod tests {
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
((), (), (5i, "a")).serialize(&mut serializer).unwrap();
|
||||
((), (), (5is, "a")).serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
|
||||
@ -702,7 +702,7 @@ mod tests {
|
||||
Token::Null,
|
||||
|
||||
Token::StructSep("b"),
|
||||
Token::Uint(5),
|
||||
Token::Usize(5),
|
||||
|
||||
Token::StructSep("c"),
|
||||
Token::MapStart(1),
|
||||
@ -749,7 +749,7 @@ mod tests {
|
||||
Token::Str("Henry"),
|
||||
|
||||
Token::EnumSep,
|
||||
Token::Int(349),
|
||||
Token::Isize(349),
|
||||
Token::EnumEnd,
|
||||
);
|
||||
|
||||
@ -766,7 +766,7 @@ mod tests {
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
let v: Vec<int> = vec!();
|
||||
let v: Vec<isize> = vec!();
|
||||
v.serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
@ -775,14 +775,14 @@ mod tests {
|
||||
fn test_tokens_vec() {
|
||||
let tokens = vec!(
|
||||
Token::SeqStart(3),
|
||||
Token::Int(5),
|
||||
Token::Int(6),
|
||||
Token::Int(7),
|
||||
Token::Isize(5),
|
||||
Token::Isize(6),
|
||||
Token::Isize(7),
|
||||
Token::SeqEnd,
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
(vec!(5i, 6, 7)).serialize(&mut serializer).unwrap();
|
||||
(vec!(5is, 6, 7)).serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
|
||||
@ -791,24 +791,24 @@ mod tests {
|
||||
let tokens = vec!(
|
||||
Token::SeqStart(3),
|
||||
Token::SeqStart(1),
|
||||
Token::Int(1),
|
||||
Token::Isize(1),
|
||||
Token::SeqEnd,
|
||||
|
||||
Token::SeqStart(2),
|
||||
Token::Int(2),
|
||||
Token::Int(3),
|
||||
Token::Isize(2),
|
||||
Token::Isize(3),
|
||||
Token::SeqEnd,
|
||||
|
||||
Token::SeqStart(3),
|
||||
Token::Int(4),
|
||||
Token::Int(5),
|
||||
Token::Int(6),
|
||||
Token::Isize(4),
|
||||
Token::Isize(5),
|
||||
Token::Isize(6),
|
||||
Token::SeqEnd,
|
||||
Token::SeqEnd,
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
(vec!(vec!(1i), vec!(2, 3), vec!(4, 5, 6))).serialize(&mut serializer).unwrap();
|
||||
(vec!(vec!(1is), vec!(2, 3), vec!(4, 5, 6))).serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
|
||||
@ -816,10 +816,10 @@ mod tests {
|
||||
fn test_tokens_treemap() {
|
||||
let tokens = vec!(
|
||||
Token::MapStart(2),
|
||||
Token::Int(5),
|
||||
Token::Isize(5),
|
||||
Token::Str("a"),
|
||||
|
||||
Token::Int(6),
|
||||
Token::Isize(6),
|
||||
Token::Str("b"),
|
||||
Token::MapEnd,
|
||||
);
|
||||
@ -827,8 +827,8 @@ mod tests {
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
|
||||
let mut map = BTreeMap::new();
|
||||
map.insert(5i, "a".to_string());
|
||||
map.insert(6i, "b".to_string());
|
||||
map.insert(5is, "a".to_string());
|
||||
map.insert(6is, "b".to_string());
|
||||
|
||||
map.serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
|
@ -4,7 +4,7 @@ extern crate serde;
|
||||
#[plugin]
|
||||
extern crate serde_macros;
|
||||
|
||||
#[derive(PartialEq, Show)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive_serialize]
|
||||
#[derive_deserialize]
|
||||
struct Test {
|
||||
@ -12,7 +12,7 @@ struct Test {
|
||||
schema: String,
|
||||
title: String,
|
||||
#[serial_name = "type"]
|
||||
ty: int
|
||||
ty: isize
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -24,8 +24,8 @@ fn test_json_struct() {
|
||||
};
|
||||
|
||||
let s = serde::json::to_string(&input).unwrap();
|
||||
assert_eq!(s.as_slice(), r#"{"$schema":"a","title":"b","type":3}"#);
|
||||
assert_eq!(&s[], r#"{"$schema":"a","title":"b","type":3}"#);
|
||||
|
||||
let output: Test = serde::json::from_str(s.as_slice()).unwrap();
|
||||
let output: Test = serde::json::from_str(&s).unwrap();
|
||||
assert_eq!(input, output);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user