mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-15 10:51:01 +00:00
wip: remove error fns from de
This commit is contained in:
+30
-18
@@ -24,6 +24,16 @@ enum Error {
|
|||||||
EndOfStreamError,
|
EndOfStreamError,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl de::Error for Error {
|
||||||
|
fn syntax_error() -> Error {
|
||||||
|
Error::SyntaxError
|
||||||
|
}
|
||||||
|
|
||||||
|
fn end_of_stream_error() -> Error {
|
||||||
|
Error::EndOfStreamError
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct MyDeserializer<Iter> {
|
struct MyDeserializer<Iter> {
|
||||||
@@ -63,6 +73,8 @@ impl<Iter: Iterator<Token>> Deserializer<Error> for MyDeserializer<Iter> {
|
|||||||
R,
|
R,
|
||||||
V: de::Visitor<MyDeserializer<Iter>, R, Error>,
|
V: de::Visitor<MyDeserializer<Iter>, R, Error>,
|
||||||
>(&mut self, visitor: &mut V) -> Result<R, Error> {
|
>(&mut self, visitor: &mut V) -> Result<R, Error> {
|
||||||
|
use serde2::de::Error;
|
||||||
|
|
||||||
match self.next() {
|
match self.next() {
|
||||||
Some(Token::Null) => {
|
Some(Token::Null) => {
|
||||||
visitor.visit_null(self)
|
visitor.visit_null(self)
|
||||||
@@ -85,10 +97,10 @@ impl<Iter: Iterator<Token>> Deserializer<Error> for MyDeserializer<Iter> {
|
|||||||
visitor.visit_map(self, MyMapVisitor { len: len })
|
visitor.visit_map(self, MyMapVisitor { len: len })
|
||||||
}
|
}
|
||||||
Some(Token::End) => {
|
Some(Token::End) => {
|
||||||
Err(self.syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
Err(self.end_of_stream_error())
|
Err(Error::end_of_stream_error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,14 +129,6 @@ impl<Iter: Iterator<Token>> Deserializer<Error> for MyDeserializer<Iter> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn syntax_error(&mut self) -> Error {
|
|
||||||
Error::SyntaxError
|
|
||||||
}
|
|
||||||
|
|
||||||
fn end_of_stream_error(&mut self) -> Error {
|
|
||||||
Error::EndOfStreamError
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MyOptionVisitor {
|
struct MyOptionVisitor {
|
||||||
@@ -157,6 +161,8 @@ impl<
|
|||||||
fn visit<
|
fn visit<
|
||||||
T: Deserialize<MyDeserializer<Iter>, Error>
|
T: Deserialize<MyDeserializer<Iter>, Error>
|
||||||
>(&mut self, d: &mut MyDeserializer<Iter>) -> Result<option::Option<T>, Error> {
|
>(&mut self, d: &mut MyDeserializer<Iter>) -> Result<option::Option<T>, Error> {
|
||||||
|
use serde2::de::Error;
|
||||||
|
|
||||||
match d.peek() {
|
match d.peek() {
|
||||||
Some(&Token::End) => {
|
Some(&Token::End) => {
|
||||||
d.next();
|
d.next();
|
||||||
@@ -168,16 +174,18 @@ impl<
|
|||||||
Ok(Some(value))
|
Ok(Some(value))
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
Err(d.syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn end(&mut self, d: &mut MyDeserializer<Iter>) -> Result<(), Error> {
|
fn end(&mut self, d: &mut MyDeserializer<Iter>) -> Result<(), Error> {
|
||||||
|
use serde2::de::Error;
|
||||||
|
|
||||||
match d.next() {
|
match d.next() {
|
||||||
Some(Token::End) => Ok(()),
|
Some(Token::End) => Ok(()),
|
||||||
Some(_) => Err(d.syntax_error()),
|
Some(_) => Err(Error::syntax_error()),
|
||||||
None => Err(d.end_of_stream_error()),
|
None => Err(Error::end_of_stream_error()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,6 +204,8 @@ impl<
|
|||||||
fn visit_key<
|
fn visit_key<
|
||||||
K: Deserialize<MyDeserializer<Iter>, Error>,
|
K: Deserialize<MyDeserializer<Iter>, Error>,
|
||||||
>(&mut self, d: &mut MyDeserializer<Iter>) -> Result<option::Option<K>, Error> {
|
>(&mut self, d: &mut MyDeserializer<Iter>) -> Result<option::Option<K>, Error> {
|
||||||
|
use serde2::de::Error;
|
||||||
|
|
||||||
match d.peek() {
|
match d.peek() {
|
||||||
Some(&Token::End) => {
|
Some(&Token::End) => {
|
||||||
d.next();
|
d.next();
|
||||||
@@ -207,7 +217,7 @@ impl<
|
|||||||
Ok(Some(try!(Deserialize::deserialize(d))))
|
Ok(Some(try!(Deserialize::deserialize(d))))
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
Err(d.syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -219,10 +229,12 @@ impl<
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn end(&mut self, d: &mut MyDeserializer<Iter>) -> Result<(), Error> {
|
fn end(&mut self, d: &mut MyDeserializer<Iter>) -> Result<(), Error> {
|
||||||
|
use serde2::de::Error;
|
||||||
|
|
||||||
match d.next() {
|
match d.next() {
|
||||||
Some(Token::End) => Ok(()),
|
Some(Token::End) => Ok(()),
|
||||||
Some(_) => Err(d.syntax_error()),
|
Some(_) => Err(Error::syntax_error()),
|
||||||
None => Err(d.end_of_stream_error()),
|
None => Err(Error::end_of_stream_error()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,14 +261,14 @@ mod json {
|
|||||||
|
|
||||||
impl<
|
impl<
|
||||||
D: de::Deserializer<E>,
|
D: de::Deserializer<E>,
|
||||||
E,
|
E: de::Error,
|
||||||
> de::Deserialize<D, E> for Value {
|
> de::Deserialize<D, E> for Value {
|
||||||
fn deserialize(d: &mut D) -> Result<Value, E> {
|
fn deserialize(d: &mut D) -> Result<Value, E> {
|
||||||
struct Visitor;
|
struct Visitor;
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
D: de::Deserializer<E>,
|
D: de::Deserializer<E>,
|
||||||
E,
|
E: de::Error,
|
||||||
> de::Visitor<D, Value, E> for Visitor {
|
> de::Visitor<D, Value, E> for Visitor {
|
||||||
fn visit_null(&mut self, _d: &mut D) -> Result<Value, E> {
|
fn visit_null(&mut self, _d: &mut D) -> Result<Value, E> {
|
||||||
Ok(Value::Null)
|
Ok(Value::Null)
|
||||||
|
|||||||
+49
-35
@@ -3,6 +3,12 @@ use std::hash::Hash;
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
pub trait Error {
|
||||||
|
fn syntax_error() -> Self;
|
||||||
|
|
||||||
|
fn end_of_stream_error() -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Deserialize<S, E> {
|
pub trait Deserialize<S, E> {
|
||||||
fn deserialize(state: &mut S) -> Result<Self, E>;
|
fn deserialize(state: &mut S) -> Result<Self, E>;
|
||||||
}
|
}
|
||||||
@@ -19,19 +25,15 @@ pub trait Deserializer<E> {
|
|||||||
>(&mut self, visitor: &mut V) -> Result<R, E> {
|
>(&mut self, visitor: &mut V) -> Result<R, E> {
|
||||||
self.visit(visitor)
|
self.visit(visitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn syntax_error(&mut self) -> E;
|
|
||||||
|
|
||||||
fn end_of_stream_error(&mut self) -> E;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Visitor<S: Deserializer<E>, R, E> {
|
pub trait Visitor<S: Deserializer<E>, R, E: Error> {
|
||||||
fn visit_null(&mut self, state: &mut S) -> Result<R, E> {
|
fn visit_null(&mut self, state: &mut S) -> Result<R, E> {
|
||||||
Err(state.syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_bool(&mut self, state: &mut S, _v: bool) -> Result<R, E> {
|
fn visit_bool(&mut self, state: &mut S, _v: bool) -> Result<R, E> {
|
||||||
Err(state.syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_int(&mut self, state: &mut S, v: int) -> Result<R, E> {
|
fn visit_int(&mut self, state: &mut S, v: int) -> Result<R, E> {
|
||||||
@@ -51,7 +53,7 @@ pub trait Visitor<S: Deserializer<E>, R, E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_i64(&mut self, state: &mut S, _v: i64) -> Result<R, E> {
|
fn visit_i64(&mut self, state: &mut S, _v: i64) -> Result<R, E> {
|
||||||
Err(state.syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_uint(&mut self, state: &mut S, v: uint) -> Result<R, E> {
|
fn visit_uint(&mut self, state: &mut S, v: uint) -> Result<R, E> {
|
||||||
@@ -71,7 +73,7 @@ pub trait Visitor<S: Deserializer<E>, R, E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_u64(&mut self, state: &mut S, _v: u64) -> Result<R, E> {
|
fn visit_u64(&mut self, state: &mut S, _v: u64) -> Result<R, E> {
|
||||||
Err(state.syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_f32(&mut self, state: &mut S, v: f32) -> Result<R, E> {
|
fn visit_f32(&mut self, state: &mut S, v: f32) -> Result<R, E> {
|
||||||
@@ -79,11 +81,11 @@ pub trait Visitor<S: Deserializer<E>, R, E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_f64(&mut self, state: &mut S, _v: f64) -> Result<R, E> {
|
fn visit_f64(&mut self, state: &mut S, _v: f64) -> Result<R, E> {
|
||||||
Err(state.syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_str(&mut self, state: &mut S, _v: &str) -> Result<R, E> {
|
fn visit_str(&mut self, state: &mut S, _v: &str) -> Result<R, E> {
|
||||||
Err(state.syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_string(&mut self, state: &mut S, v: String) -> Result<R, E> {
|
fn visit_string(&mut self, state: &mut S, v: String) -> Result<R, E> {
|
||||||
@@ -93,19 +95,19 @@ pub trait Visitor<S: Deserializer<E>, R, E> {
|
|||||||
fn visit_option<
|
fn visit_option<
|
||||||
V: OptionVisitor<S, E>,
|
V: OptionVisitor<S, E>,
|
||||||
>(&mut self, state: &mut S, _visitor: V) -> Result<R, E> {
|
>(&mut self, state: &mut S, _visitor: V) -> Result<R, E> {
|
||||||
Err(state.syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_seq<
|
fn visit_seq<
|
||||||
V: SeqVisitor<S, E>,
|
V: SeqVisitor<S, E>,
|
||||||
>(&mut self, state: &mut S, _visitor: V) -> Result<R, E> {
|
>(&mut self, state: &mut S, _visitor: V) -> Result<R, E> {
|
||||||
Err(state.syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_map<
|
fn visit_map<
|
||||||
V: MapVisitor<S, E>,
|
V: MapVisitor<S, E>,
|
||||||
>(&mut self, state: &mut S, _visitor: V) -> Result<R, E> {
|
>(&mut self, state: &mut S, _visitor: V) -> Result<R, E> {
|
||||||
Err(state.syntax_error())
|
Err(Error::syntax_error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,12 +164,15 @@ pub trait MapVisitor<S, E> {
|
|||||||
|
|
||||||
impl<
|
impl<
|
||||||
S: Deserializer<E>,
|
S: Deserializer<E>,
|
||||||
E,
|
E: Error,
|
||||||
> Deserialize<S, E> for () {
|
> Deserialize<S, E> for () {
|
||||||
fn deserialize(state: &mut S) -> Result<(), E> {
|
fn deserialize(state: &mut S) -> Result<(), E> {
|
||||||
struct Visitor;
|
struct Visitor;
|
||||||
|
|
||||||
impl<S: Deserializer<E>, E> self::Visitor<S, (), E> for Visitor {
|
impl<
|
||||||
|
S: Deserializer<E>,
|
||||||
|
E: Error,
|
||||||
|
> self::Visitor<S, (), E> for Visitor {
|
||||||
fn visit_null(&mut self, _state: &mut S) -> Result<(), E> {
|
fn visit_null(&mut self, _state: &mut S) -> Result<(), E> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -188,12 +193,15 @@ impl<
|
|||||||
|
|
||||||
impl<
|
impl<
|
||||||
S: Deserializer<E>,
|
S: Deserializer<E>,
|
||||||
E,
|
E: Error,
|
||||||
> Deserialize<S, E> for bool {
|
> Deserialize<S, E> for bool {
|
||||||
fn deserialize(state: &mut S) -> Result<bool, E> {
|
fn deserialize(state: &mut S) -> Result<bool, E> {
|
||||||
struct Visitor;
|
struct Visitor;
|
||||||
|
|
||||||
impl<S: Deserializer<E>, E> self::Visitor<S, bool, E> for Visitor {
|
impl<
|
||||||
|
S: Deserializer<E>,
|
||||||
|
E: Error,
|
||||||
|
> self::Visitor<S, bool, E> for Visitor {
|
||||||
fn visit_bool(&mut self, _state: &mut S, v: bool) -> Result<bool, E> {
|
fn visit_bool(&mut self, _state: &mut S, v: bool) -> Result<bool, E> {
|
||||||
Ok(v)
|
Ok(v)
|
||||||
}
|
}
|
||||||
@@ -210,7 +218,7 @@ macro_rules! impl_deserialize_num_method {
|
|||||||
fn $method(&mut self, state: &mut S, v: $src_ty) -> Result<T, E> {
|
fn $method(&mut self, state: &mut S, v: $src_ty) -> Result<T, E> {
|
||||||
match FromPrimitive::$from_method(v) {
|
match FromPrimitive::$from_method(v) {
|
||||||
Some(v) => Ok(v),
|
Some(v) => Ok(v),
|
||||||
None => Err(state.syntax_error()),
|
None => Err(Error::syntax_error()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -219,14 +227,14 @@ macro_rules! impl_deserialize_num_method {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn deserialize_from_primitive<
|
pub fn deserialize_from_primitive<
|
||||||
S: Deserializer<E>,
|
S: Deserializer<E>,
|
||||||
E,
|
E: Error,
|
||||||
T: Deserialize<S, E> + FromPrimitive
|
T: Deserialize<S, E> + FromPrimitive
|
||||||
>(state: &mut S) -> Result<T, E> {
|
>(state: &mut S) -> Result<T, E> {
|
||||||
struct Visitor;
|
struct Visitor;
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
S: Deserializer<E>,
|
S: Deserializer<E>,
|
||||||
E,
|
E: Error,
|
||||||
T: Deserialize<S, E> + FromPrimitive
|
T: Deserialize<S, E> + FromPrimitive
|
||||||
> self::Visitor<S, T, E> for Visitor {
|
> self::Visitor<S, T, E> for Visitor {
|
||||||
impl_deserialize_num_method!(int, visit_int, from_int)
|
impl_deserialize_num_method!(int, visit_int, from_int)
|
||||||
@@ -248,7 +256,10 @@ pub fn deserialize_from_primitive<
|
|||||||
|
|
||||||
macro_rules! impl_deserialize_num {
|
macro_rules! impl_deserialize_num {
|
||||||
($ty:ty) => {
|
($ty:ty) => {
|
||||||
impl<S: Deserializer<E>, E> Deserialize<S, E> for $ty {
|
impl<
|
||||||
|
S: Deserializer<E>,
|
||||||
|
E: Error,
|
||||||
|
> Deserialize<S, E> for $ty {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deserialize(state: &mut S) -> Result<$ty, E> {
|
fn deserialize(state: &mut S) -> Result<$ty, E> {
|
||||||
deserialize_from_primitive(state)
|
deserialize_from_primitive(state)
|
||||||
@@ -274,12 +285,15 @@ impl_deserialize_num!(f64)
|
|||||||
|
|
||||||
impl<
|
impl<
|
||||||
S: Deserializer<E>,
|
S: Deserializer<E>,
|
||||||
E,
|
E: Error,
|
||||||
> Deserialize<S, E> for String {
|
> Deserialize<S, E> for String {
|
||||||
fn deserialize(state: &mut S) -> Result<String, E> {
|
fn deserialize(state: &mut S) -> Result<String, E> {
|
||||||
struct Visitor;
|
struct Visitor;
|
||||||
|
|
||||||
impl<S: Deserializer<E>, E> self::Visitor<S, String, E> for Visitor {
|
impl<
|
||||||
|
S: Deserializer<E>,
|
||||||
|
E: Error,
|
||||||
|
> self::Visitor<S, String, E> for Visitor {
|
||||||
fn visit_str(&mut self, _state: &mut S, v: &str) -> Result<String, E> {
|
fn visit_str(&mut self, _state: &mut S, v: &str) -> Result<String, E> {
|
||||||
Ok(v.to_string())
|
Ok(v.to_string())
|
||||||
}
|
}
|
||||||
@@ -298,7 +312,7 @@ impl<
|
|||||||
impl<
|
impl<
|
||||||
T: Deserialize<S, E>,
|
T: Deserialize<S, E>,
|
||||||
S: Deserializer<E>,
|
S: Deserializer<E>,
|
||||||
E,
|
E: Error,
|
||||||
> Deserialize<S, E> for Option<T> {
|
> Deserialize<S, E> for Option<T> {
|
||||||
fn deserialize(state: &mut S) -> Result<Option<T>, E> {
|
fn deserialize(state: &mut S) -> Result<Option<T>, E> {
|
||||||
struct Visitor;
|
struct Visitor;
|
||||||
@@ -306,7 +320,7 @@ impl<
|
|||||||
impl<
|
impl<
|
||||||
T: Deserialize<S, E>,
|
T: Deserialize<S, E>,
|
||||||
S: Deserializer<E>,
|
S: Deserializer<E>,
|
||||||
E,
|
E: Error,
|
||||||
> self::Visitor<S, Option<T>, E> for Visitor {
|
> self::Visitor<S, Option<T>, E> for Visitor {
|
||||||
fn visit_option<
|
fn visit_option<
|
||||||
V: OptionVisitor<S, E>,
|
V: OptionVisitor<S, E>,
|
||||||
@@ -324,7 +338,7 @@ impl<
|
|||||||
impl<
|
impl<
|
||||||
T: Deserialize<S, E>,
|
T: Deserialize<S, E>,
|
||||||
S: Deserializer<E>,
|
S: Deserializer<E>,
|
||||||
E,
|
E: Error,
|
||||||
> Deserialize<S, E> for Vec<T> {
|
> Deserialize<S, E> for Vec<T> {
|
||||||
fn deserialize(state: &mut S) -> Result<Vec<T>, E> {
|
fn deserialize(state: &mut S) -> Result<Vec<T>, E> {
|
||||||
struct Visitor;
|
struct Visitor;
|
||||||
@@ -332,7 +346,7 @@ impl<
|
|||||||
impl<
|
impl<
|
||||||
T: Deserialize<S, E>,
|
T: Deserialize<S, E>,
|
||||||
S: Deserializer<E>,
|
S: Deserializer<E>,
|
||||||
E,
|
E: Error,
|
||||||
> self::Visitor<S, Vec<T>, E> for Visitor {
|
> self::Visitor<S, Vec<T>, E> for Visitor {
|
||||||
fn visit_seq<
|
fn visit_seq<
|
||||||
V: SeqVisitor<S, E>,
|
V: SeqVisitor<S, E>,
|
||||||
@@ -374,7 +388,7 @@ macro_rules! impl_deserialize_tuple {
|
|||||||
|
|
||||||
impl<
|
impl<
|
||||||
S: Deserializer<E>,
|
S: Deserializer<E>,
|
||||||
E,
|
E: Error,
|
||||||
$($name: Deserialize<S, E>),+
|
$($name: Deserialize<S, E>),+
|
||||||
> Deserialize<S, E> for ($($name,)+) {
|
> Deserialize<S, E> for ($($name,)+) {
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -384,7 +398,7 @@ macro_rules! impl_deserialize_tuple {
|
|||||||
|
|
||||||
impl<
|
impl<
|
||||||
S: Deserializer<E>,
|
S: Deserializer<E>,
|
||||||
E,
|
E: Error,
|
||||||
$($name: Deserialize<S, E>,)+
|
$($name: Deserialize<S, E>,)+
|
||||||
> self::Visitor<S, ($($name,)+), E> for Visitor {
|
> self::Visitor<S, ($($name,)+), E> for Visitor {
|
||||||
fn visit_seq<
|
fn visit_seq<
|
||||||
@@ -393,7 +407,7 @@ macro_rules! impl_deserialize_tuple {
|
|||||||
$(
|
$(
|
||||||
let $name = match try!(visitor.visit(state)) {
|
let $name = match try!(visitor.visit(state)) {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => { return Err(state.end_of_stream_error()); }
|
None => { return Err(Error::end_of_stream_error()); }
|
||||||
};
|
};
|
||||||
)+;
|
)+;
|
||||||
|
|
||||||
@@ -417,7 +431,7 @@ impl<
|
|||||||
K: Deserialize<S, E> + Eq + Hash,
|
K: Deserialize<S, E> + Eq + Hash,
|
||||||
V: Deserialize<S, E>,
|
V: Deserialize<S, E>,
|
||||||
S: Deserializer<E>,
|
S: Deserializer<E>,
|
||||||
E,
|
E: Error,
|
||||||
> Deserialize<S, E> for HashMap<K, V> {
|
> Deserialize<S, E> for HashMap<K, V> {
|
||||||
fn deserialize(state: &mut S) -> Result<HashMap<K, V>, E> {
|
fn deserialize(state: &mut S) -> Result<HashMap<K, V>, E> {
|
||||||
struct Visitor;
|
struct Visitor;
|
||||||
@@ -426,7 +440,7 @@ impl<
|
|||||||
K: Deserialize<S, E> + Eq + Hash,
|
K: Deserialize<S, E> + Eq + Hash,
|
||||||
V: Deserialize<S, E>,
|
V: Deserialize<S, E>,
|
||||||
S: Deserializer<E>,
|
S: Deserializer<E>,
|
||||||
E,
|
E: Error,
|
||||||
> self::Visitor<S, HashMap<K, V>, E> for Visitor {
|
> self::Visitor<S, HashMap<K, V>, E> for Visitor {
|
||||||
fn visit_map<
|
fn visit_map<
|
||||||
Visitor: MapVisitor<S, E>,
|
Visitor: MapVisitor<S, E>,
|
||||||
@@ -457,7 +471,7 @@ impl<
|
|||||||
K: Deserialize<S, E> + Eq + Ord,
|
K: Deserialize<S, E> + Eq + Ord,
|
||||||
V: Deserialize<S, E>,
|
V: Deserialize<S, E>,
|
||||||
S: Deserializer<E>,
|
S: Deserializer<E>,
|
||||||
E,
|
E: Error,
|
||||||
> Deserialize<S, E> for TreeMap<K, V> {
|
> Deserialize<S, E> for TreeMap<K, V> {
|
||||||
fn deserialize(state: &mut S) -> Result<TreeMap<K, V>, E> {
|
fn deserialize(state: &mut S) -> Result<TreeMap<K, V>, E> {
|
||||||
struct Visitor;
|
struct Visitor;
|
||||||
@@ -466,7 +480,7 @@ impl<
|
|||||||
K: Deserialize<S, E> + Eq + Ord,
|
K: Deserialize<S, E> + Eq + Ord,
|
||||||
V: Deserialize<S, E>,
|
V: Deserialize<S, E>,
|
||||||
S: Deserializer<E>,
|
S: Deserializer<E>,
|
||||||
E,
|
E: Error,
|
||||||
> self::Visitor<S, TreeMap<K, V>, E> for Visitor {
|
> self::Visitor<S, TreeMap<K, V>, E> for Visitor {
|
||||||
fn visit_map<
|
fn visit_map<
|
||||||
Visitor: MapVisitor<S, E>,
|
Visitor: MapVisitor<S, E>,
|
||||||
|
|||||||
@@ -387,14 +387,6 @@ impl<Iter: Iterator<u8>> Deserializer<Error> for Parser<Iter> {
|
|||||||
>(&mut self, visitor: &mut V) -> Result<R, Error> {
|
>(&mut self, visitor: &mut V) -> Result<R, Error> {
|
||||||
self.parse_value(visitor)
|
self.parse_value(visitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn syntax_error(&mut self) -> Error {
|
|
||||||
Error::SyntaxError(ErrorCode::ExpectedSomeValue, self.line, self.col)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn end_of_stream_error(&mut self) -> Error {
|
|
||||||
Error::SyntaxError(ErrorCode::EOFWhileParsingValue, self.line, self.col)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SeqVisitor {
|
struct SeqVisitor {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ use std::error;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
|
use de;
|
||||||
|
|
||||||
/// The errors that can arise while parsing a JSON stream.
|
/// The errors that can arise while parsing a JSON stream.
|
||||||
#[deriving(Clone, PartialEq)]
|
#[deriving(Clone, PartialEq)]
|
||||||
pub enum ErrorCode {
|
pub enum ErrorCode {
|
||||||
@@ -124,3 +126,13 @@ impl error::FromError<io::IoError> for Error {
|
|||||||
Error::IoError(error)
|
Error::IoError(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl de::Error for Error {
|
||||||
|
fn syntax_error() -> Error {
|
||||||
|
Error::SyntaxError(ErrorCode::ExpectedSomeValue, 0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn end_of_stream_error() -> Error {
|
||||||
|
Error::SyntaxError(ErrorCode::EOFWhileParsingValue, 0, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user