mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-12 23:41:03 +00:00
Update to rust HEAD
This commit is contained in:
+8
-8
@@ -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),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::collections::{HashMap, BTreeMap};
|
||||
use std::hash::Hash;
|
||||
use std::num::FromPrimitive;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#![feature(macro_rules)]
|
||||
|
||||
extern crate unicode;
|
||||
|
||||
pub use ser::{Serialize, Serializer};
|
||||
|
||||
+89
-82
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user