Update to rust HEAD

This commit is contained in:
Erick Tryzelaar 2015-01-07 07:51:59 -08:00
parent b98719a4a0
commit 8715a41158
23 changed files with 295 additions and 255 deletions

View File

@ -1,6 +1,6 @@
#![feature(associated_types, phase, old_orphan_check)]
#![feature(plugin)]
#[phase(plugin)]
#[plugin]
extern crate serde_macros;
extern crate serde;
@ -63,7 +63,9 @@ mod decoder {
}
}
impl Decoder<Error> for AnimalDecoder {
impl Decoder for AnimalDecoder {
type Error = Error;
fn error(&mut self, msg: &str) -> Error {
OtherError(msg.to_string())
}

View File

@ -1,7 +1,7 @@
#![feature(phase, macro_rules, old_orphan_check)]
#![feature(plugin)]
#![allow(non_camel_case_types)]
#[phase(plugin)]
#[plugin]
extern crate serde_macros;
extern crate serde;
@ -44,14 +44,14 @@ enum HttpProtocol {
HTTP11,
}
impl<S: rustc_serialize::Encoder<E>, E> rustc_serialize::Encodable<S, E> for HttpProtocol {
fn encode(&self, s: &mut S) -> Result<(), E> {
impl rustc_serialize::Encodable for HttpProtocol {
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
(*self as uint).encode(s)
}
}
impl<D: rustc_serialize::Decoder<E>, E> rustc_serialize::Decodable<D, E> for HttpProtocol {
fn decode(d: &mut D) -> Result<HttpProtocol, E> {
impl rustc_serialize::Decodable for HttpProtocol {
fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<HttpProtocol, D::Error> {
match FromPrimitive::from_uint(try!(d.read_uint())) {
Some(value) => Ok(value),
None => Err(d.error("cannot convert from uint")),
@ -88,14 +88,14 @@ enum HttpMethod {
PATCH,
}
impl<S: rustc_serialize::Encoder<E>, E> rustc_serialize::Encodable<S, E> for HttpMethod {
fn encode(&self, s: &mut S) -> Result<(), E> {
impl rustc_serialize::Encodable for HttpMethod {
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
(*self as uint).encode(s)
}
}
impl<D: rustc_serialize::Decoder<E>, E> rustc_serialize::Decodable<D, E> for HttpMethod {
fn decode(d: &mut D) -> Result<HttpMethod, E> {
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_uint())) {
Some(value) => Ok(value),
None => Err(d.error("cannot convert from uint")),
@ -125,14 +125,14 @@ enum CacheStatus {
Hit,
}
impl<S: rustc_serialize::Encoder<E>, E> rustc_serialize::Encodable<S, E> for CacheStatus {
fn encode(&self, s: &mut S) -> Result<(), E> {
impl rustc_serialize::Encodable for CacheStatus {
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
(*self as uint).encode(s)
}
}
impl<D: rustc_serialize::Decoder<E>, E> rustc_serialize::Decodable<D, E> for CacheStatus {
fn decode(d: &mut D) -> Result<CacheStatus, E> {
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_uint())) {
Some(value) => Ok(value),
None => Err(d.error("cannot convert from uint")),
@ -171,14 +171,14 @@ enum OriginProtocol {
HTTPS,
}
impl<S: rustc_serialize::Encoder<E>, E> rustc_serialize::Encodable<S, E> for OriginProtocol {
fn encode(&self, s: &mut S) -> Result<(), E> {
impl rustc_serialize::Encodable for OriginProtocol {
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
(*self as uint).encode(s)
}
}
impl<D: rustc_serialize::Decoder<E>, E> rustc_serialize::Decodable<D, E> for OriginProtocol {
fn decode(d: &mut D) -> Result<OriginProtocol, E> {
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_uint())) {
Some(value) => Ok(value),
None => Err(d.error("cannot convert from uint")),
@ -209,14 +209,14 @@ enum ZonePlan {
ENT,
}
impl<S: rustc_serialize::Encoder<E>, E> rustc_serialize::Encodable<S, E> for ZonePlan {
fn encode(&self, s: &mut S) -> Result<(), E> {
impl rustc_serialize::Encodable for ZonePlan {
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
(*self as uint).encode(s)
}
}
impl<D: rustc_serialize::Decoder<E>, E> rustc_serialize::Decodable<D, E> for ZonePlan {
fn decode(d: &mut D) -> Result<ZonePlan, E> {
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_uint())) {
Some(value) => Ok(value),
None => Err(d.error("cannot convert from uint")),
@ -498,14 +498,14 @@ enum Country {
ZW,
}
impl<S: rustc_serialize::Encoder<E>, E> rustc_serialize::Encodable<S, E> for Country {
fn encode(&self, s: &mut S) -> Result<(), E> {
impl rustc_serialize::Encodable for Country {
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
(*self as uint).encode(s)
}
}
impl<D: rustc_serialize::Decoder<E>, E> rustc_serialize::Decodable<D, E> for Country {
fn decode(d: &mut D) -> Result<Country, E> {
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_uint())) {
Some(value) => Ok(value),
None => Err(d.error("cannot convert from uint")),

View File

@ -1,23 +1,23 @@
#![feature(associated_types, phase)]
#![feature(plugin)]
#[phase(plugin)]
#[plugin]
extern crate serde_macros;
extern crate serde;
extern crate serialize;
extern crate "rustc-serialize" as rustc_serialize;
extern crate test;
use std::fmt::Show;
use std::collections::HashMap;
use test::Bencher;
use serialize::{Decoder, Decodable};
use rustc_serialize::{Decoder, Decodable};
use serde::de::{Deserializer, Deserialize};
//////////////////////////////////////////////////////////////////////////////
#[derive(Show)]
#[derive(PartialEq, Show)]
pub enum Error {
EndOfStream,
SyntaxError,
@ -29,7 +29,7 @@ pub enum Error {
mod decoder {
use std::collections::HashMap;
use std::collections::hash_map::IntoIter;
use serialize;
use rustc_serialize;
use super::Error;
use super::Error::{EndOfStream, SyntaxError, OtherError};
@ -57,7 +57,9 @@ mod decoder {
}
}
impl serialize::Decoder<Error> for IntDecoder {
impl rustc_serialize::Decoder for IntDecoder {
type Error = Error;
fn error(&mut self, msg: &str) -> Error {
OtherError(msg.to_string())
}
@ -318,13 +320,12 @@ mod deserializer {
//////////////////////////////////////////////////////////////////////////////
fn run_decoder<
E: Show,
D: Decoder<E>,
T: Clone + PartialEq + Show + Decodable<D, E>
D: Decoder<Error=Error>,
T: Clone + PartialEq + Show + Decodable
>(mut d: D, value: T) {
let v: T = Decodable::decode(&mut d).unwrap();
let v = Decodable::decode(&mut d);
assert_eq!(value, v);
assert_eq!(Ok(value), v);
}
#[bench]

View File

@ -1,6 +1,6 @@
#![feature(associated_types, phase, old_orphan_check)]
#![feature(plugin)]
#[phase(plugin)]
#[plugin]
extern crate serde_macros;
extern crate serde;
@ -91,7 +91,9 @@ mod decoder {
}
}
impl Decoder<Error> for OuterDecoder {
impl Decoder for OuterDecoder {
type Error = Error;
fn error(&mut self, msg: &str) -> Error {
Error::OtherError(msg.to_string())
}

View File

@ -1,6 +1,6 @@
#![feature(associated_types, phase)]
#![feature(plugin)]
#[phase(plugin)]
#[plugin]
extern crate serde_macros;
extern crate serde;
@ -16,7 +16,7 @@ use serde::de::{Deserializer, Deserialize};
//////////////////////////////////////////////////////////////////////////////
#[derive(Show)]
#[derive(PartialEq, Show)]
pub enum Error {
EndOfStream,
SyntaxError,
@ -47,7 +47,9 @@ mod decoder {
}
}
impl rustc_serialize::Decoder<Error> for IntDecoder {
impl rustc_serialize::Decoder for IntDecoder {
type Error = Error;
fn error(&mut self, msg: &str) -> Error {
OtherError(msg.to_string())
}
@ -199,7 +201,9 @@ mod decoder {
}
}
impl rustc_serialize::Decoder<Error> for U8Decoder {
impl rustc_serialize::Decoder for U8Decoder {
type Error = Error;
fn error(&mut self, msg: &str) -> Error {
OtherError(msg.to_string())
}
@ -508,13 +512,12 @@ mod deserializer {
//////////////////////////////////////////////////////////////////////////////
fn run_decoder<
D: Decoder<E>,
E: Show,
T: Clone + PartialEq + Show + Decodable<D, E>
D: Decoder<Error=Error>,
T: Clone + PartialEq + Show + Decodable
>(mut d: D, value: T) {
let v: T = Decodable::decode(&mut d).unwrap();
let v = Decodable::decode(&mut d);
assert_eq!(value, v);
assert_eq!(Ok(value), v);
}
fn run_deserializer<

6
serde2/Cargo.lock generated
View File

@ -2,9 +2,15 @@
name = "serde2"
version = "0.1.0"
dependencies = [
"rustc-serialize 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde2_macros 0.1.0",
]
[[package]]
name = "rustc-serialize"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde2_macros"
version = "0.1.0"

View File

@ -10,5 +10,8 @@ name = "serde2"
name = "serde2"
path = "src/bin.rs"
[dependencies]
rustc-serialize = "*"
[dependencies.serde2_macros]
path = "serde2_macros/"

View File

@ -1,15 +1,16 @@
#![feature(phase, macro_rules)]
#![feature(plugin)]
#![allow(non_camel_case_types)]
#[phase(plugin)]
#[plugin]
extern crate serde2_macros;
extern crate serde2;
extern crate serialize;
extern crate "rustc-serialize" as rustc_serialize;
extern crate test;
use std::io;
use std::io::ByRefWriter;
use std::num::FromPrimitive;
use test::Bencher;
use serde2::json::ser::escape_str;
@ -19,7 +20,7 @@ use serde2::ser;
use serde2::de::{Deserialize, Deserializer};
use serde2::de;
use serialize::Encodable;
use rustc_serialize::Encodable;
enum HttpField {
Protocol,
@ -66,9 +67,9 @@ impl<
}
}
#[deriving(Show, PartialEq, Encodable, Decodable)]
#[deriving_serialize]
//#[deriving_deserialize]
#[derive(Show, PartialEq, RustcEncodable, RustcDecodable)]
#[derive_serialize]
//#[derive_deserialize]
struct Http {
protocol: HttpProtocol,
status: u32,
@ -141,21 +142,21 @@ impl<
}
}
#[deriving(Copy, Show, PartialEq, FromPrimitive)]
#[derive(Copy, Show, PartialEq, FromPrimitive)]
enum HttpProtocol {
HTTP_PROTOCOL_UNKNOWN,
HTTP10,
HTTP11,
}
impl<S: serialize::Encoder<E>, E> serialize::Encodable<S, E> for HttpProtocol {
fn encode(&self, s: &mut S) -> Result<(), E> {
impl rustc_serialize::Encodable for HttpProtocol {
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
(*self as uint).encode(s)
}
}
impl<D: ::serialize::Decoder<E>, E> serialize::Decodable<D, E> for HttpProtocol {
fn decode(d: &mut D) -> Result<HttpProtocol, E> {
impl rustc_serialize::Decodable for HttpProtocol {
fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<HttpProtocol, D::Error> {
match FromPrimitive::from_uint(try!(d.read_uint())) {
Some(value) => Ok(value),
None => Err(d.error("cannot convert from uint")),
@ -185,7 +186,7 @@ impl<
}
}
#[deriving(Copy, Show, PartialEq, FromPrimitive)]
#[derive(Copy, Show, PartialEq, FromPrimitive)]
enum HttpMethod {
METHOD_UNKNOWN,
GET,
@ -200,14 +201,14 @@ enum HttpMethod {
PATCH,
}
impl<S: serialize::Encoder<E>, E> serialize::Encodable<S, E> for HttpMethod {
fn encode(&self, s: &mut S) -> Result<(), E> {
impl rustc_serialize::Encodable for HttpMethod {
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
(*self as uint).encode(s)
}
}
impl<D: ::serialize::Decoder<E>, E> serialize::Decodable<D, E> for HttpMethod {
fn decode(d: &mut D) -> Result<HttpMethod, E> {
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_uint())) {
Some(value) => Ok(value),
None => Err(d.error("cannot convert from uint")),
@ -237,7 +238,7 @@ impl<
}
}
#[deriving(Copy, Show, PartialEq, FromPrimitive)]
#[derive(Copy, Show, PartialEq, FromPrimitive)]
enum CacheStatus {
CACHESTATUS_UNKNOWN,
Miss,
@ -245,14 +246,14 @@ enum CacheStatus {
Hit,
}
impl<S: serialize::Encoder<E>, E> serialize::Encodable<S, E> for CacheStatus {
fn encode(&self, s: &mut S) -> Result<(), E> {
impl rustc_serialize::Encodable for CacheStatus {
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
(*self as uint).encode(s)
}
}
impl<D: ::serialize::Decoder<E>, E> serialize::Decodable<D, E> for CacheStatus {
fn decode(d: &mut D) -> Result<CacheStatus, E> {
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_uint())) {
Some(value) => Ok(value),
None => Err(d.error("cannot convert from uint")),
@ -314,9 +315,9 @@ impl<
}
}
#[deriving(Show, PartialEq, Encodable, Decodable)]
#[deriving_serialize]
//#[deriving_deserialize]
#[derive(Show, PartialEq, RustcEncodable, RustcDecodable)]
#[derive_serialize]
//#[derive_deserialize]
struct Origin {
ip: String,
port: u32,
@ -370,21 +371,21 @@ impl<
}
}
#[deriving(Copy, Show, PartialEq, FromPrimitive)]
#[derive(Copy, Show, PartialEq, FromPrimitive)]
enum OriginProtocol {
ORIGIN_PROTOCOL_UNKNOWN,
HTTP,
HTTPS,
}
impl<S: serialize::Encoder<E>, E> serialize::Encodable<S, E> for OriginProtocol {
fn encode(&self, s: &mut S) -> Result<(), E> {
impl rustc_serialize::Encodable for OriginProtocol {
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
(*self as uint).encode(s)
}
}
impl<D: ::serialize::Decoder<E>, E> serialize::Decodable<D, E> for OriginProtocol {
fn decode(d: &mut D) -> Result<OriginProtocol, E> {
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_uint())) {
Some(value) => Ok(value),
None => Err(d.error("cannot convert from uint")),
@ -411,7 +412,7 @@ impl<S: de::Deserializer<E>, E: de::Error> de::Deserialize<S, E> for OriginProto
}
}
#[deriving(Copy, Show, PartialEq, FromPrimitive)]
#[derive(Copy, Show, PartialEq, FromPrimitive)]
enum ZonePlan {
ZONEPLAN_UNKNOWN,
FREE,
@ -420,14 +421,14 @@ enum ZonePlan {
ENT,
}
impl<S: serialize::Encoder<E>, E> serialize::Encodable<S, E> for ZonePlan {
fn encode(&self, s: &mut S) -> Result<(), E> {
impl rustc_serialize::Encodable for ZonePlan {
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
(*self as uint).encode(s)
}
}
impl<D: ::serialize::Decoder<E>, E> serialize::Decodable<D, E> for ZonePlan {
fn decode(d: &mut D) -> Result<ZonePlan, E> {
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_uint())) {
Some(value) => Ok(value),
None => Err(d.error("cannot convert from uint")),
@ -454,7 +455,7 @@ impl<S: de::Deserializer<E>, E: de::Error> de::Deserialize<S, E> for ZonePlan {
}
}
#[deriving(Copy, Show, PartialEq, FromPrimitive)]
#[derive(Copy, Show, PartialEq, FromPrimitive)]
enum Country {
UNKNOWN,
A1,
@ -714,14 +715,14 @@ enum Country {
ZW,
}
impl<S: serialize::Encoder<E>, E> serialize::Encodable<S, E> for Country {
fn encode(&self, s: &mut S) -> Result<(), E> {
impl rustc_serialize::Encodable for Country {
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
(*self as uint).encode(s)
}
}
impl<D: ::serialize::Decoder<E>, E> serialize::Decodable<D, E> for Country {
fn decode(d: &mut D) -> Result<Country, E> {
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_uint())) {
Some(value) => Ok(value),
None => Err(d.error("cannot convert from uint")),
@ -799,9 +800,9 @@ impl<
}
}
#[deriving(Show, PartialEq, Encodable, Decodable)]
#[deriving_serialize]
//#[deriving_deserialize]
#[derive(Show, PartialEq, RustcEncodable, RustcDecodable)]
#[derive_serialize]
//#[derive_deserialize]
struct Log {
timestamp: i64,
zone_id: u32,
@ -1012,14 +1013,14 @@ const JSON_STR: &'static str = r#"{"timestamp":2837513946597,"zone_id":123456,"z
#[test]
fn test_encoder() {
use serialize::Encodable;
use rustc_serialize::Encodable;
let log = Log::new();
let mut wr = Vec::with_capacity(1024);
{
let mut encoder = serialize::json::Encoder::new(&mut wr as &mut Writer);
let mut encoder = rustc_serialize::json::Encoder::new(&mut wr);
log.encode(&mut encoder).unwrap();
}
@ -1033,7 +1034,7 @@ fn bench_encoder(b: &mut Bencher) {
let mut wr = Vec::with_capacity(1024);
{
let mut encoder = serialize::json::Encoder::new(&mut wr as &mut Writer);
let mut encoder = rustc_serialize::json::Encoder::new(&mut wr);
log.encode(&mut encoder).unwrap();
}
@ -1042,7 +1043,7 @@ fn bench_encoder(b: &mut Bencher) {
b.iter(|| {
wr.clear();
let mut encoder = serialize::json::Encoder::new(&mut wr as &mut Writer);
let mut encoder = rustc_serialize::json::Encoder::new(&mut wr);
log.encode(&mut encoder).unwrap();
});
}
@ -1099,7 +1100,7 @@ fn bench_serializer_slice(b: &mut Bencher) {
let json = json::to_vec(&log).unwrap();
b.bytes = json.len() as u64;
let mut buf = [0, .. 1024];
let mut buf = [0; 1024];
b.iter(|| {
for item in buf.iter_mut(){ *item = 0; }

View File

@ -48,17 +48,17 @@ use rustc::plugin::Registry;
#[doc(hidden)]
pub fn plugin_registrar(reg: &mut Registry) {
reg.register_syntax_extension(
token::intern("deriving_serialize"),
Decorator(box expand_deriving_serialize));
token::intern("derive_serialize"),
Decorator(box expand_derive_serialize));
/*
reg.register_syntax_extension(
token::intern("deriving_deserialize"),
ItemDecorator(box expand_deriving_deserialize));
token::intern("derive_deserialize"),
ItemDecorator(box expand_derive_deserialize));
*/
}
fn expand_deriving_serialize<>(cx: &mut ExtCtxt,
fn expand_derive_serialize<>(cx: &mut ExtCtxt,
sp: Span,
mitem: &MetaItem,
item: &Item,
@ -121,7 +121,7 @@ fn expand_deriving_serialize<>(cx: &mut ExtCtxt,
)
),
attributes: attrs,
combine_substructure: combine_substructure(|a, b, c| {
combine_substructure: combine_substructure(box |a, b, c| {
serialize_substructure(a, b, c)
}),
}
@ -148,7 +148,7 @@ fn serialize_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) -> P<
serialize_enum(cx, span, state, visitor, substr.type_ident, variant, fields)
}
_ => cx.bug("expected Struct or EnumMatching in deriving_serialize")
_ => cx.bug("expected Struct or EnumMatching in derive_serialize")
}
}
@ -261,7 +261,7 @@ fn serialize_enum(cx: &ExtCtxt,
}
/*
pub fn expand_deriving_deserialize(cx: &mut ExtCtxt,
pub fn expand_derive_deserialize(cx: &mut ExtCtxt,
span: Span,
mitem: &MetaItem,
item: &Item,
@ -304,7 +304,7 @@ pub fn expand_deriving_deserialize(cx: &mut ExtCtxt,
)
),
attributes: Vec::new(),
combine_substructure: combine_substructure(|a, b, c| {
combine_substructure: combine_substructure(box |a, b, c| {
deserialize_substructure(a, b, c)
}),
})
@ -337,7 +337,7 @@ fn deserialize_substructure(cx: &mut ExtCtxt, span: Span,
deserializer,
token)
}
_ => cx.bug("expected StaticEnum or StaticStruct in deriving(Deserialize)")
_ => cx.bug("expected StaticEnum or StaticStruct in derive(Deserialize)")
}
}

View File

@ -7,7 +7,7 @@ use std::string;
use serde2::de;
use serde2::de::{Deserialize, Deserializer};
#[deriving(Show)]
#[derive(Show)]
pub enum Token {
Null,
Int(int),
@ -18,7 +18,7 @@ pub enum Token {
End,
}
#[deriving(Show)]
#[derive(Show)]
enum Error {
SyntaxError,
EndOfStreamError,
@ -41,7 +41,7 @@ struct MyDeserializer<Iter> {
peeked: option::Option<Token>,
}
impl<Iter: Iterator<Token>> MyDeserializer<Iter> {
impl<Iter: Iterator<Item=Token>> MyDeserializer<Iter> {
pub fn new(tokens: Iter) -> MyDeserializer<Iter> {
MyDeserializer {
tokens: tokens,
@ -68,7 +68,7 @@ impl<Iter: Iterator<Token>> MyDeserializer<Iter> {
}
}
impl<Iter: Iterator<Token>> Deserializer<Error> for MyDeserializer<Iter> {
impl<Iter: Iterator<Item=Token>> Deserializer<Error> for MyDeserializer<Iter> {
fn visit<
R,
V: de::Visitor<MyDeserializer<Iter>, R, Error>,
@ -139,7 +139,7 @@ struct MyOptionVisitor<'a, Iter: 'a> {
impl<
'a,
Iter: Iterator<Token>,
Iter: Iterator<Item=Token>,
> de::OptionVisitor<MyDeserializer<Iter>, Error> for MyOptionVisitor<'a, Iter> {
fn visit<
T: Deserialize<MyDeserializer<Iter>, Error>,
@ -161,7 +161,7 @@ struct MySeqVisitor<'a, Iter: 'a> {
impl<
'a,
Iter: Iterator<Token>,
Iter: Iterator<Item=Token>,
> de::SeqVisitor<MyDeserializer<Iter>, Error> for MySeqVisitor<'a, Iter> {
fn visit<
T: Deserialize<MyDeserializer<Iter>, Error>
@ -206,7 +206,7 @@ struct MyMapVisitor<'a, Iter: 'a> {
impl<
'a,
Iter: Iterator<Token>,
Iter: Iterator<Item=Token>,
> de::MapVisitor<MyDeserializer<Iter>, Error> for MyMapVisitor<'a, Iter> {
fn visit_key<
K: Deserialize<MyDeserializer<Iter>, Error>,
@ -256,7 +256,7 @@ mod json {
use std::collections::BTreeMap;
use serde2::de;
#[deriving(Show)]
#[derive(Show)]
pub enum Value {
Null,
//Bool(bool),

View File

@ -1,5 +1,6 @@
use std::collections::{HashMap, BTreeMap};
use std::hash::Hash;
use std::num::FromPrimitive;
///////////////////////////////////////////////////////////////////////////////

View File

@ -10,8 +10,8 @@
use std::collections::BTreeMap;
use ser::{mod, Serialize};
use json::value::{mod, Value};
use ser::{self, Serialize};
use json::value::{self, Value};
pub struct ArrayBuilder {
array: Vec<Value>,
@ -31,13 +31,17 @@ impl ArrayBuilder {
self
}
pub fn push_array(mut self, f: |ArrayBuilder| -> ArrayBuilder) -> ArrayBuilder {
pub fn push_array<F>(mut self, f: F) -> ArrayBuilder where
F: FnOnce(ArrayBuilder) -> ArrayBuilder
{
let builder = ArrayBuilder::new();
self.array.push(f(builder).unwrap());
self
}
pub fn push_object(mut self, f: |ObjectBuilder| -> ObjectBuilder) -> ArrayBuilder {
pub fn push_object<F>(mut self, f: F) -> ArrayBuilder where
F: FnOnce(ObjectBuilder) -> ObjectBuilder
{
let builder = ObjectBuilder::new();
self.array.push(f(builder).unwrap());
self
@ -62,13 +66,17 @@ impl ObjectBuilder {
self
}
pub fn insert_array(mut self, key: String, f: |ArrayBuilder| -> ArrayBuilder) -> ObjectBuilder {
pub fn insert_array<F>(mut self, key: String, f: F) -> ObjectBuilder where
F: FnOnce(ArrayBuilder) -> ArrayBuilder
{
let builder = ArrayBuilder::new();
self.object.insert(key, f(builder).unwrap());
self
}
pub fn insert_object(mut self, key: String, f: |ObjectBuilder| -> ObjectBuilder) -> ObjectBuilder {
pub fn insert_object<F>(mut self, key: String, f: F) -> ObjectBuilder where
F: FnOnce(ObjectBuilder) -> ObjectBuilder
{
let builder = ObjectBuilder::new();
self.object.insert(key, f(builder).unwrap());
self

View File

@ -15,7 +15,7 @@ pub struct Parser<Iter> {
buf: Vec<u8>,
}
impl<Iter: Iterator<u8>> Parser<Iter> {
impl<Iter: Iterator<Item=u8>> Parser<Iter> {
/// Creates the JSON parser.
#[inline]
pub fn new(rdr: Iter) -> Parser<Iter> {
@ -353,7 +353,7 @@ impl<Iter: Iterator<u8>> Parser<Iter> {
}
};
let buf = &mut [0u8, .. 4];
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));
}
@ -380,7 +380,7 @@ impl<Iter: Iterator<u8>> Parser<Iter> {
}
}
impl<Iter: Iterator<u8>> Deserializer<Error> for Parser<Iter> {
impl<Iter: Iterator<Item=u8>> Deserializer<Error> for Parser<Iter> {
#[inline]
fn visit<
R,
@ -395,7 +395,7 @@ struct SeqVisitor<'a, Iter: 'a> {
first: bool,
}
impl<'a, Iter: Iterator<u8>> de::SeqVisitor<Parser<Iter>, Error> for SeqVisitor<'a, Iter> {
impl<'a, Iter: Iterator<Item=u8>> de::SeqVisitor<Parser<Iter>, Error> for SeqVisitor<'a, Iter> {
fn visit<
T: de::Deserialize<Parser<Iter>, Error>,
>(&mut self) -> Result<Option<T>, Error> {
@ -439,7 +439,7 @@ struct MapVisitor<'a, Iter: 'a> {
first: bool,
}
impl<'a, Iter: Iterator<u8>> de::MapVisitor<Parser<Iter>, Error> for MapVisitor<'a, Iter> {
impl<'a, Iter: Iterator<Item=u8>> de::MapVisitor<Parser<Iter>, Error> for MapVisitor<'a, Iter> {
fn visit_key<
K: de::Deserialize<Parser<Iter>, Error>,
>(&mut self) -> Result<Option<K>, Error> {
@ -506,7 +506,7 @@ impl<'a, Iter: Iterator<u8>> de::MapVisitor<Parser<Iter>, Error> for MapVisitor<
/// Decodes a json value from an `Iterator<u8>`.
pub fn from_iter<
Iter: Iterator<u8>,
Iter: Iterator<Item=u8>,
T: de::Deserialize<Parser<Iter>, Error>
>(iter: Iter) -> Result<T, Error> {
let mut parser = Parser::new(iter);

View File

@ -5,7 +5,7 @@ use std::io;
use de;
/// The errors that can arise while parsing a JSON stream.
#[deriving(Copy, Clone, PartialEq)]
#[derive(Copy, Clone, PartialEq)]
pub enum ErrorCode {
EOFWhileParsingList,
EOFWhileParsingObject,
@ -75,7 +75,7 @@ impl fmt::Show for ErrorCode {
}
}
#[deriving(Clone, PartialEq, Show)]
#[derive(Clone, PartialEq, Show)]
pub enum Error {
/// msg, line, col
SyntaxError(ErrorCode, uint, uint),

View File

@ -1,5 +1,5 @@
use std::f64;
use std::io::{mod, ByRefWriter, IoError};
use std::io::{self, ByRefWriter, IoError};
use std::num::{Float, FpCategory};
use std::string::FromUtf8Error;
@ -218,7 +218,7 @@ pub fn escape_str<W: io::Writer>(wr: &mut W, value: &str) -> Result<(), IoError>
#[inline]
pub fn escape_char<W: io::Writer>(wr: &mut W, value: char) -> Result<(), IoError> {
let mut buf = &mut [0, .. 4];
let mut buf = &mut [0; 4];
value.encode_utf8(buf);
escape_bytes(wr, buf)
}

View File

@ -1,10 +1,11 @@
use std::collections::BTreeMap;
use std::fmt;
use std::io;
use std::str;
use ser::{mod, Serializer};
use ser::{self, Serializer};
#[deriving(PartialEq)]
#[derive(PartialEq)]
pub enum Value {
Null,
Bool(bool),
@ -49,19 +50,20 @@ impl ser::Serialize for Value {
}
}
struct WriterFormatter<'a, 'b: 'a>(&'a mut fmt::Formatter<'b>);
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<()> {
let WriterFormatter(ref mut f) = *self;
f.write(buf).map_err(|_| io::IoError::last_error())
self.inner.write_str(str::from_utf8(buf).unwrap()).map_err(|_| io::IoError::last_error())
}
}
impl fmt::Show for Value {
/// Serializes a json value into a string
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut wr = WriterFormatter(f);
let mut wr = WriterFormatter { inner: f };
super::ser::to_writer(&mut wr, self).map_err(|_| fmt::Error)
}
}

View File

@ -1,5 +1,3 @@
#![feature(macro_rules)]
extern crate unicode;
pub use ser::{Serialize, Serializer};

View File

@ -224,7 +224,7 @@ pub struct SeqIteratorVisitor<Iter> {
first: bool,
}
impl<T, Iter: Iterator<T>> SeqIteratorVisitor<Iter> {
impl<T, Iter: Iterator<Item=T>> SeqIteratorVisitor<Iter> {
#[inline]
pub fn new(iter: Iter) -> SeqIteratorVisitor<Iter> {
SeqIteratorVisitor {
@ -236,7 +236,7 @@ impl<T, Iter: Iterator<T>> SeqIteratorVisitor<Iter> {
impl<
T: Serialize,
Iter: Iterator<T>,
Iter: Iterator<Item=T>,
S,
R,
E,
@ -281,10 +281,15 @@ impl<
///////////////////////////////////////////////////////////////////////////////
// FIXME(rust #19630) Remove this work-around
macro_rules! e {
($e:expr) => { $e }
}
macro_rules! tuple_impls {
($(
($($T:ident),+) {
$($state:pat => $method:ident,)+
$($state:pat => $idx:tt,)+
}
)+) => {
$(
@ -317,8 +322,10 @@ macro_rules! tuple_impls {
$(
$state => {
self.state += 1;
let value = self.tuple.$method();
let value = try!(visitor.visit_seq_elt(state, true, value));
let value = try!(visitor.visit_seq_elt(
state,
true,
&e!(self.tuple.$idx)));
Ok(Some(value))
}
)+
@ -341,101 +348,101 @@ macro_rules! tuple_impls {
tuple_impls! {
(T0) {
0 => ref0,
0 => 0,
}
(T0, T1) {
0 => ref0,
1 => ref1,
0 => 0,
1 => 1,
}
(T0, T1, T2, T3) {
0 => ref0,
1 => ref1,
2 => ref2,
3 => ref3,
0 => 0,
1 => 1,
2 => 2,
3 => 3,
}
(T0, T1, T2, T3, T4) {
0 => ref0,
1 => ref1,
2 => ref2,
3 => ref3,
4 => ref4,
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
}
(T0, T1, T2, T3, T4, T5) {
0 => ref0,
1 => ref1,
2 => ref2,
3 => ref3,
4 => ref4,
5 => ref5,
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
}
(T0, T1, T2, T3, T4, T5, T6) {
0 => ref0,
1 => ref1,
2 => ref2,
3 => ref3,
4 => ref4,
5 => ref5,
6 => ref6,
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
}
(T0, T1, T2, T3, T4, T5, T6, T7) {
0 => ref0,
1 => ref1,
2 => ref2,
3 => ref3,
4 => ref4,
5 => ref5,
6 => ref6,
7 => ref7,
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
}
(T0, T1, T2, T3, T4, T5, T6, T7, T8) {
0 => ref0,
1 => ref1,
2 => ref2,
3 => ref3,
4 => ref4,
5 => ref5,
6 => ref6,
7 => ref7,
8 => ref8,
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
}
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) {
0 => ref0,
1 => ref1,
2 => ref2,
3 => ref3,
4 => ref4,
5 => ref5,
6 => ref6,
7 => ref7,
8 => ref8,
9 => ref9,
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
}
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) {
0 => ref0,
1 => ref1,
2 => ref2,
3 => ref3,
4 => ref4,
5 => ref5,
6 => ref6,
7 => ref7,
8 => ref8,
9 => ref9,
10 => ref10,
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
10 => 10,
}
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) {
0 => ref0,
1 => ref1,
2 => ref2,
3 => ref3,
4 => ref4,
5 => ref5,
6 => ref6,
7 => ref7,
8 => ref8,
9 => ref9,
10 => ref10,
11 => ref11,
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
10 => 10,
11 => 11,
}
}
@ -446,7 +453,7 @@ pub struct MapIteratorVisitor<Iter> {
first: bool,
}
impl<K, V, Iter: Iterator<(K, V)>> MapIteratorVisitor<Iter> {
impl<K, V, Iter: Iterator<Item=(K, V)>> MapIteratorVisitor<Iter> {
#[inline]
pub fn new(iter: Iter) -> MapIteratorVisitor<Iter> {
MapIteratorVisitor {
@ -459,7 +466,7 @@ impl<K, V, Iter: Iterator<(K, V)>> MapIteratorVisitor<Iter> {
impl<
K: Serialize,
V: Serialize,
Iter: Iterator<(K, V)>,
Iter: Iterator<Item=(K, V)>,
S,
R,
E,

View File

@ -107,7 +107,7 @@ fn expand_derive_serialize(cx: &mut ExtCtxt,
)
),
attributes: attrs,
combine_substructure: combine_substructure(|a, b, c| {
combine_substructure: combine_substructure(box |a, b, c| {
serialize_substructure(a, b, c, item)
}),
})
@ -238,7 +238,7 @@ pub fn expand_derive_deserialize(cx: &mut ExtCtxt,
)
),
attributes: Vec::new(),
combine_substructure: combine_substructure(|a, b, c| {
combine_substructure: combine_substructure(box |a, b, c| {
deserialize_substructure(a, b, c)
}),
})
@ -415,7 +415,7 @@ fn deserialize_enum(
path,
serial_names.as_slice(),
parts,
|cx, _, _| {
|&: cx, _, _| {
quote_expr!(cx, try!($deserializer.expect_enum_elt()))
}
);
@ -441,14 +441,14 @@ fn deserialize_enum(
/// Create a deserializer for a single enum variant/struct:
/// - `outer_pat_ident` is the name of this enum variant/struct
/// - `getarg` should retrieve the `uint`-th field with name `&str`.
fn deserialize_static_fields(
fn deserialize_static_fields<F>(
cx: &ExtCtxt,
span: Span,
outer_pat_path: ast::Path,
serial_names: &[Option<token::InternedString>],
fields: &StaticFields,
getarg: |&ExtCtxt, Span, token::InternedString| -> P<Expr>
) -> P<Expr> {
getarg: F
) -> P<Expr> where F: Fn(&ExtCtxt, Span, token::InternedString) -> P<Expr> {
match *fields {
Unnamed(ref fields) => {
let path_expr = cx.expr_path(outer_pat_path);

View File

@ -31,12 +31,16 @@ impl ArrayBuilder {
builder
}
pub fn push_array(self, f: |ArrayBuilder| -> ArrayBuilder) -> ArrayBuilder {
pub fn push_array<F>(self, f: F) -> ArrayBuilder where
F: FnOnce(ArrayBuilder) -> ArrayBuilder
{
let builder = ArrayBuilder::new();
self.push(f(builder).unwrap())
}
pub fn push_object(self, f: |ObjectBuilder| -> ObjectBuilder) -> ArrayBuilder {
pub fn push_object<F>(self, f: F) -> ArrayBuilder where
F: FnOnce(ObjectBuilder) -> ObjectBuilder
{
let builder = ObjectBuilder::new();
self.push(f(builder).unwrap())
}
@ -61,12 +65,16 @@ impl ObjectBuilder {
builder
}
pub fn insert_array(self, key: String, f: |ArrayBuilder| -> ArrayBuilder) -> ObjectBuilder {
pub fn insert_array<F>(self, key: String, f: F) -> ObjectBuilder where
F: FnOnce(ArrayBuilder) -> ArrayBuilder
{
let builder = ArrayBuilder::new();
self.insert(key, f(builder).unwrap())
}
pub fn insert_object(self, key: String, f: |ObjectBuilder| -> ObjectBuilder) -> ObjectBuilder {
pub fn insert_object<F>(self, key: String, f: F) -> ObjectBuilder where
F: FnOnce(ObjectBuilder) -> ObjectBuilder
{
let builder = ObjectBuilder::new();
self.insert(key, f(builder).unwrap())
}

View File

@ -60,8 +60,8 @@ the code for these traits: `#[derive_serialize]` and `#[derive_deserialize]`.
To serialize using `Serialize`:
```rust
#![feature(phase, old_orphan_check)]
#[phase(plugin)]
#![feature(plugin)]
#[plugin]
extern crate serde_macros;
extern crate serde;
@ -110,8 +110,8 @@ A basic `ToJson` example using a BTreeMap of attribute name / attribute value:
```rust
#![feature(phase, old_orphan_check)]
#[phase(plugin)]
#![feature(plugin)]
#[plugin]
extern crate serde_macros;
extern crate serde;
@ -142,8 +142,8 @@ fn main() {
Or you can use the helper type `ObjectBuilder`:
```rust
#![feature(phase, old_orphan_check)]
#[phase(plugin)]
#![feature(plugin)]
#[plugin]
extern crate serde_macros;
extern crate serde;
@ -173,8 +173,8 @@ fn main() {
To deserialize a JSON string using `Deserialize` trait:
```rust
#![feature(phase, old_orphan_check)]
#[phase(plugin)]
#![feature(plugin)]
#[plugin]
extern crate serde_macros;
extern crate serde;
@ -205,8 +205,8 @@ Create a struct called `TestStruct1` and serialize and deserialize it to and fro
using the serialization API, using the derived serialization code.
```rust
#![feature(phase, old_orphan_check)]
#[phase(plugin)]
#![feature(plugin)]
#[plugin]
extern crate serde_macros;
extern crate serde;
@ -245,8 +245,8 @@ This example use the ToJson impl to deserialize the JSON string.
Example of `ToJson` trait implementation for TestStruct1.
```rust
#![feature(phase, old_orphan_check)]
#[phase(plugin)]
#![feature(plugin)]
#[plugin]
extern crate serde_macros;
extern crate serde;
@ -1792,7 +1792,7 @@ mod bench {
let json = encoder_json(count);
b.iter(|| {
assert_eq!(json.pretty().to_string(), src);
assert_eq!(json.to_string(), src);
});
}

View File

@ -1,14 +1,12 @@
#![feature(macro_rules, phase)]
#![feature(plugin)]
#![crate_type = "dylib"]
#![crate_type = "rlib"]
#![feature(associated_types, old_orphan_check)]
// test harness access
#[cfg(test)]
extern crate test;
#[phase(plugin)]
#[plugin]
extern crate serde_macros;
#[cfg(test)]

View File

@ -1,7 +1,7 @@
#![feature(phase, old_orphan_check)]
#![feature(plugin)]
extern crate serde;
#[phase(plugin)]
#[plugin]
extern crate serde_macros;
#[derive(PartialEq, Show)]