mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 05:31:02 +00:00
wip: initial progress converting serde2 to associated types
This commit is contained in:
+3
-3
@@ -6,9 +6,9 @@ authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
|||||||
[lib]
|
[lib]
|
||||||
name = "serde2"
|
name = "serde2"
|
||||||
|
|
||||||
[[bin]]
|
#[[bin]]
|
||||||
name = "serde2"
|
#name = "serde2"
|
||||||
path = "src/bin.rs"
|
#path = "src/bin.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rustc-serialize = "*"
|
rustc-serialize = "*"
|
||||||
|
|||||||
+60
-46
@@ -11,108 +11,117 @@ pub trait Error {
|
|||||||
fn end_of_stream_error() -> Self;
|
fn end_of_stream_error() -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Deserialize<S, E> {
|
pub trait Deserialize<S: Deserializer> {
|
||||||
fn deserialize(state: &mut S) -> Result<Self, E>;
|
type Visitor: Visitor<S, Self>;
|
||||||
|
|
||||||
|
fn deserialize(state: &mut S) -> Result<Self, S::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Deserializer<E> {
|
pub trait Deserializer {
|
||||||
|
type Error: Error;
|
||||||
|
|
||||||
fn visit<
|
fn visit<
|
||||||
R,
|
R,
|
||||||
V: Visitor<Self, R, E>,
|
V: Visitor<Self, R>,
|
||||||
>(&mut self, visitor: &mut V) -> Result<R, E>;
|
>(&mut self, visitor: &mut V) -> Result<R, Self::Error>;
|
||||||
|
|
||||||
|
/*
|
||||||
fn visit_option<
|
fn visit_option<
|
||||||
R,
|
R,
|
||||||
V: Visitor<Self, R, E>,
|
V: Visitor<Self, R, E>,
|
||||||
>(&mut self, visitor: &mut V) -> Result<R, E> {
|
>(&mut self, visitor: &mut V) -> Result<R, S::Error> {
|
||||||
self.visit(visitor)
|
self.visit(visitor)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Visitor<S: Deserializer<E>, R, E: Error> {
|
pub trait Visitor<S: Deserializer, R> {
|
||||||
fn visit_null(&mut self) -> Result<R, E> {
|
fn visit_null(&mut self) -> Result<R, S::Error> {
|
||||||
Err(Error::syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_bool(&mut self, _v: bool) -> Result<R, E> {
|
/*
|
||||||
|
fn visit_bool(&mut self, _v: bool) -> Result<R, S::Error> {
|
||||||
Err(Error::syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_int(&mut self, v: int) -> Result<R, E> {
|
fn visit_int(&mut self, v: int) -> Result<R, S::Error> {
|
||||||
self.visit_i64(v as i64)
|
self.visit_i64(v as i64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_i8(&mut self, v: i8) -> Result<R, E> {
|
fn visit_i8(&mut self, v: i8) -> Result<R, S::Error> {
|
||||||
self.visit_i64(v as i64)
|
self.visit_i64(v as i64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_i16(&mut self, v: i16) -> Result<R, E> {
|
fn visit_i16(&mut self, v: i16) -> Result<R, S::Error> {
|
||||||
self.visit_i64(v as i64)
|
self.visit_i64(v as i64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_i32(&mut self, v: i32) -> Result<R, E> {
|
fn visit_i32(&mut self, v: i32) -> Result<R, S::Error> {
|
||||||
self.visit_i64(v as i64)
|
self.visit_i64(v as i64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_i64(&mut self, _v: i64) -> Result<R, E> {
|
fn visit_i64(&mut self, _v: i64) -> Result<R, S::Error> {
|
||||||
Err(Error::syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_uint(&mut self, v: uint) -> Result<R, E> {
|
fn visit_uint(&mut self, v: uint) -> Result<R, S::Error> {
|
||||||
self.visit_u64(v as u64)
|
self.visit_u64(v as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_u8(&mut self, v: u8) -> Result<R, E> {
|
fn visit_u8(&mut self, v: u8) -> Result<R, S::Error> {
|
||||||
self.visit_u64(v as u64)
|
self.visit_u64(v as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_u16(&mut self, v: u16) -> Result<R, E> {
|
fn visit_u16(&mut self, v: u16) -> Result<R, S::Error> {
|
||||||
self.visit_u64(v as u64)
|
self.visit_u64(v as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_u32(&mut self, v: u32) -> Result<R, E> {
|
fn visit_u32(&mut self, v: u32) -> Result<R, S::Error> {
|
||||||
self.visit_u64(v as u64)
|
self.visit_u64(v as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_u64(&mut self, _v: u64) -> Result<R, E> {
|
fn visit_u64(&mut self, _v: u64) -> Result<R, S::Error> {
|
||||||
Err(Error::syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_f32(&mut self, v: f32) -> Result<R, E> {
|
fn visit_f32(&mut self, v: f32) -> Result<R, S::Error> {
|
||||||
self.visit_f64(v as f64)
|
self.visit_f64(v as f64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_f64(&mut self, _v: f64) -> Result<R, E> {
|
fn visit_f64(&mut self, _v: f64) -> Result<R, S::Error> {
|
||||||
Err(Error::syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_str<'a>(&'a mut self, _v: &'a str) -> Result<R, E> {
|
fn visit_str<'a>(&'a mut self, _v: &'a str) -> Result<R, S::Error> {
|
||||||
Err(Error::syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_string(&mut self, v: String) -> Result<R, E> {
|
fn visit_string(&mut self, v: String) -> Result<R, S::Error> {
|
||||||
self.visit_str(v.as_slice())
|
self.visit_str(v.as_slice())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_option<
|
fn visit_option<
|
||||||
V: OptionVisitor<S, E>,
|
V: OptionVisitor<S, E>,
|
||||||
>(&mut self, _visitor: V) -> Result<R, E> {
|
>(&mut self, _visitor: V) -> Result<R, S::Error> {
|
||||||
Err(Error::syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_seq<
|
fn visit_seq<
|
||||||
V: SeqVisitor<S, E>,
|
V: SeqVisitor<S, E>,
|
||||||
>(&mut self, _visitor: V) -> Result<R, E> {
|
>(&mut self, _visitor: V) -> Result<R, S::Error> {
|
||||||
Err(Error::syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_map<
|
fn visit_map<
|
||||||
V: MapVisitor<S, E>,
|
V: MapVisitor<S, E>,
|
||||||
>(&mut self, _visitor: V) -> Result<R, E> {
|
>(&mut self, _visitor: V) -> Result<R, S::Error> {
|
||||||
Err(Error::syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
pub trait OptionVisitor<S, E> {
|
pub trait OptionVisitor<S, E> {
|
||||||
fn visit<
|
fn visit<
|
||||||
T: Deserialize<S, E>,
|
T: Deserialize<S, E>,
|
||||||
@@ -163,34 +172,38 @@ pub trait MapVisitor<S, E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct UnitVisitor;
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
S: Deserializer<E>,
|
S: Deserializer,
|
||||||
E: Error,
|
> Visitor<S, ()> for UnitVisitor {
|
||||||
> Deserialize<S, E> for () {
|
fn visit_null(&mut self) -> Result<(), S::Error> {
|
||||||
fn deserialize(state: &mut S) -> Result<(), E> {
|
Ok(())
|
||||||
struct Visitor;
|
}
|
||||||
|
|
||||||
impl<
|
/*
|
||||||
S: Deserializer<E>,
|
fn visit_seq<
|
||||||
E: Error,
|
V: SeqVisitor<S, E>,
|
||||||
> self::Visitor<S, (), E> for Visitor {
|
>(&mut self, mut visitor: V) -> Result<(), E> {
|
||||||
fn visit_null(&mut self) -> Result<(), E> {
|
try!(visitor.end());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_seq<
|
impl<
|
||||||
V: SeqVisitor<S, E>,
|
S: Deserializer,
|
||||||
>(&mut self, mut visitor: V) -> Result<(), E> {
|
> Deserialize<S> for () {
|
||||||
try!(visitor.end());
|
type Visitor = UnitVisitor;
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
state.visit(&mut Visitor)
|
fn deserialize(state: &mut S) -> Result<(), S::Error> {
|
||||||
|
state.visit(&mut UnitVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
@@ -507,3 +520,4 @@ impl<
|
|||||||
state.visit(&mut Visitor)
|
state.visit(&mut Visitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
extern crate unicode;
|
extern crate unicode;
|
||||||
|
|
||||||
pub use ser::{Serialize, Serializer};
|
//pub use ser::{Serialize, Serializer};
|
||||||
//pub use ser::{Visitor, VisitorState};
|
//pub use ser::{Visitor, VisitorState};
|
||||||
//pub use ser::GatherTokens;
|
//pub use ser::GatherTokens;
|
||||||
|
|
||||||
pub mod ser;
|
pub mod ser;
|
||||||
pub mod de;
|
//pub mod de;
|
||||||
pub mod json;
|
//pub mod json;
|
||||||
|
|||||||
+710
-188
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user