mirror of
https://github.com/serde-rs/serde.git
synced 2025-10-01 23:11:18 +00:00
start cleaning up error handling
This commit is contained in:
parent
ea5936aa78
commit
c58958b1c8
@ -28,7 +28,7 @@ impl<E, D: Deserializer<E>> Deserializable<E, D> for Animal {
|
|||||||
|
|
||||||
Ok(Frog(x0, x1))
|
Ok(Frog(x0, x1))
|
||||||
}
|
}
|
||||||
_ => Err(d.syntax_error()),
|
_ => d.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -247,13 +247,13 @@ mod deserializer {
|
|||||||
|
|
||||||
impl Deserializer<Error> for AnimalDeserializer {
|
impl Deserializer<Error> for AnimalDeserializer {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn end_of_stream_error(&self) -> Error {
|
fn end_of_stream_error<T>(&self) -> Result<T, Error> {
|
||||||
EndOfStream
|
Err(EndOfStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn syntax_error(&self) -> Error {
|
fn syntax_error<T>(&self) -> Result<T, Error> {
|
||||||
SyntaxError
|
Err(SyntaxError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,13 +221,13 @@ mod deserializer {
|
|||||||
|
|
||||||
impl de::Deserializer<Error> for IntDeserializer {
|
impl de::Deserializer<Error> for IntDeserializer {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn end_of_stream_error(&self) -> Error {
|
fn end_of_stream_error<T>(&self) -> Result<T, Error> {
|
||||||
EndOfStream
|
Err(EndOfStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn syntax_error(&self) -> Error {
|
fn syntax_error<T>(&self) -> Result<T, Error> {
|
||||||
SyntaxError
|
Err(SyntaxError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ impl<E, D: Deserializer<E>> Deserializable<E, D> for Inner {
|
|||||||
_ => { }
|
_ => { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => { return Err(d.syntax_error()); }
|
_ => { return d.syntax_error(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,10 +64,10 @@ impl<E, D: Deserializer<E>> Deserializable<E, D> for Inner {
|
|||||||
(Some(a), Some(b), Some(c)) => {
|
(Some(a), Some(b), Some(c)) => {
|
||||||
Ok(Inner { a: a, b: b, c: c })
|
Ok(Inner { a: a, b: b, c: c })
|
||||||
}
|
}
|
||||||
_ => Err(d.syntax_error()),
|
_ => d.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(d.syntax_error()),
|
_ => d.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ impl<E, D: Deserializer<E>> Deserializable<E, D> for Outer {
|
|||||||
_ => { }
|
_ => { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => { return Err(d.syntax_error()); }
|
_ => { return d.syntax_error(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,10 +114,10 @@ impl<E, D: Deserializer<E>> Deserializable<E, D> for Outer {
|
|||||||
Some(inner) => {
|
Some(inner) => {
|
||||||
Ok(Outer { inner: inner })
|
Ok(Outer { inner: inner })
|
||||||
}
|
}
|
||||||
_ => Err(d.syntax_error()),
|
_ => d.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(d.syntax_error()),
|
_ => d.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -446,13 +446,13 @@ mod deserializer {
|
|||||||
|
|
||||||
impl Deserializer<Error> for OuterDeserializer {
|
impl Deserializer<Error> for OuterDeserializer {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn end_of_stream_error(&self) -> Error {
|
fn end_of_stream_error<T>(&self) -> Result<T, Error> {
|
||||||
EndOfStream
|
Err(EndOfStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn syntax_error(&self) -> Error {
|
fn syntax_error<T>(&self) -> Result<T, Error> {
|
||||||
SyntaxError
|
Err(SyntaxError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
bench_vec.rs
16
bench_vec.rs
@ -284,13 +284,13 @@ mod deserializer {
|
|||||||
|
|
||||||
impl de::Deserializer<Error> for IntDeserializer {
|
impl de::Deserializer<Error> for IntDeserializer {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn end_of_stream_error(&self) -> Error {
|
fn end_of_stream_error<T>(&self) -> Result<T, Error> {
|
||||||
EndOfStream
|
Err(EndOfStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn syntax_error(&self) -> Error {
|
fn syntax_error<T>(&self) -> Result<T, Error> {
|
||||||
SyntaxError
|
Err(SyntaxError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,13 +339,13 @@ mod deserializer {
|
|||||||
|
|
||||||
impl de::Deserializer<Error> for U8Deserializer {
|
impl de::Deserializer<Error> for U8Deserializer {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn end_of_stream_error(&self) -> Error {
|
fn end_of_stream_error<T>(&self) -> Result<T, Error> {
|
||||||
EndOfStream
|
Err(EndOfStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn syntax_error(&self) -> Error {
|
fn syntax_error<T>(&self) -> Result<T, Error> {
|
||||||
SyntaxError
|
Err(SyntaxError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
84
de.rs
84
de.rs
@ -38,22 +38,22 @@ macro_rules! to_result {
|
|||||||
($expr:expr, $err:expr) => {
|
($expr:expr, $err:expr) => {
|
||||||
match $expr {
|
match $expr {
|
||||||
Some(value) => Ok(value),
|
Some(value) => Ok(value),
|
||||||
None => Err($err),
|
None => $err,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
||||||
fn end_of_stream_error(&self) -> E;
|
fn end_of_stream_error<T>(&self) -> Result<T, E>;
|
||||||
|
|
||||||
fn syntax_error(&self) -> E;
|
fn syntax_error<T>(&self) -> Result<T, E>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn expect_token(&mut self) -> Result<Token, E> {
|
fn expect_token(&mut self) -> Result<Token, E> {
|
||||||
match self.next() {
|
match self.next() {
|
||||||
Some(Ok(token)) => Ok(token),
|
Some(Ok(token)) => Ok(token),
|
||||||
Some(Err(err)) => Err(err),
|
Some(Err(err)) => Err(err),
|
||||||
None => Err(self.end_of_stream_error()),
|
None => self.end_of_stream_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,10 +64,10 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
|||||||
TupleStart(_) => {
|
TupleStart(_) => {
|
||||||
match try!(self.expect_token()) {
|
match try!(self.expect_token()) {
|
||||||
End => Ok(()),
|
End => Ok(()),
|
||||||
_ => Err(self.syntax_error()),
|
_ => self.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(self.syntax_error()),
|
_ => self.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
|||||||
fn expect_bool(&mut self, token: Token) -> Result<bool, E> {
|
fn expect_bool(&mut self, token: Token) -> Result<bool, E> {
|
||||||
match token {
|
match token {
|
||||||
Bool(value) => Ok(value),
|
Bool(value) => Ok(value),
|
||||||
_ => Err(self.syntax_error()),
|
_ => self.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
|||||||
U64(x) => to_result!(num::cast(x), self.syntax_error()),
|
U64(x) => to_result!(num::cast(x), self.syntax_error()),
|
||||||
F32(x) => to_result!(num::cast(x), self.syntax_error()),
|
F32(x) => to_result!(num::cast(x), self.syntax_error()),
|
||||||
F64(x) => to_result!(num::cast(x), self.syntax_error()),
|
F64(x) => to_result!(num::cast(x), self.syntax_error()),
|
||||||
_ => Err(self.syntax_error()),
|
_ => self.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
|||||||
fn expect_char(&mut self, token: Token) -> Result<char, E> {
|
fn expect_char(&mut self, token: Token) -> Result<char, E> {
|
||||||
match token {
|
match token {
|
||||||
Char(value) => Ok(value),
|
Char(value) => Ok(value),
|
||||||
_ => Err(self.syntax_error()),
|
_ => self.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
|||||||
fn expect_str(&mut self, token: Token) -> Result<&'static str, E> {
|
fn expect_str(&mut self, token: Token) -> Result<&'static str, E> {
|
||||||
match token {
|
match token {
|
||||||
Str(value) => Ok(value),
|
Str(value) => Ok(value),
|
||||||
_ => Err(self.syntax_error()),
|
_ => self.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
|||||||
match token {
|
match token {
|
||||||
Str(value) => Ok(value.to_string()),
|
Str(value) => Ok(value.to_string()),
|
||||||
String(value) => Ok(value),
|
String(value) => Ok(value),
|
||||||
_ => Err(self.syntax_error()),
|
_ => self.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
|||||||
let value: T = try!(Deserializable::deserialize(self));
|
let value: T = try!(Deserializable::deserialize(self));
|
||||||
Ok(Some(value))
|
Ok(Some(value))
|
||||||
}
|
}
|
||||||
_ => Err(self.syntax_error()),
|
_ => self.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,10 +144,10 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
|||||||
if len == l {
|
if len == l {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(self.syntax_error())
|
self.syntax_error()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(self.syntax_error()),
|
_ => self.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,10 +158,10 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
|||||||
if name == n {
|
if name == n {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(self.syntax_error())
|
self.syntax_error()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(self.syntax_error()),
|
_ => self.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,15 +172,15 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
|||||||
match try!(self.expect_token()) {
|
match try!(self.expect_token()) {
|
||||||
Str(n) => {
|
Str(n) => {
|
||||||
if name != n {
|
if name != n {
|
||||||
return Err(self.syntax_error());
|
return self.syntax_error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String(n) => {
|
String(n) => {
|
||||||
if name != n.as_slice() {
|
if name != n.as_slice() {
|
||||||
return Err(self.syntax_error());
|
return self.syntax_error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => { return Err(self.syntax_error()); }
|
_ => { return self.syntax_error(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
Deserializable::deserialize(self)
|
Deserializable::deserialize(self)
|
||||||
@ -193,13 +193,13 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
|||||||
if name == n {
|
if name == n {
|
||||||
match variants.iter().position(|variant| *variant == v) {
|
match variants.iter().position(|variant| *variant == v) {
|
||||||
Some(position) => Ok(position),
|
Some(position) => Ok(position),
|
||||||
None => Err(self.syntax_error()),
|
None => self.syntax_error(),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(self.syntax_error())
|
self.syntax_error()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(self.syntax_error()),
|
_ => self.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
|||||||
TupleStart(len) => len,
|
TupleStart(len) => len,
|
||||||
SeqStart(len) => len,
|
SeqStart(len) => len,
|
||||||
MapStart(len) => len,
|
MapStart(len) => len,
|
||||||
_ => { return Err(self.syntax_error()); }
|
_ => { return self.syntax_error(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
expect_rest_of_collection(self, len)
|
expect_rest_of_collection(self, len)
|
||||||
@ -227,7 +227,7 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
|||||||
fn expect_seq_start(&mut self, token: Token) -> Result<uint, E> {
|
fn expect_seq_start(&mut self, token: Token) -> Result<uint, E> {
|
||||||
match token {
|
match token {
|
||||||
SeqStart(len) => Ok(len),
|
SeqStart(len) => Ok(len),
|
||||||
_ => Err(self.syntax_error()),
|
_ => self.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +235,7 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
|||||||
fn expect_map_start(&mut self, token: Token) -> Result<uint, E> {
|
fn expect_map_start(&mut self, token: Token) -> Result<uint, E> {
|
||||||
match token {
|
match token {
|
||||||
MapStart(len) => Ok(len),
|
MapStart(len) => Ok(len),
|
||||||
_ => Err(self.syntax_error()),
|
_ => self.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +243,7 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
|||||||
fn expect_end(&mut self) -> Result<(), E> {
|
fn expect_end(&mut self) -> Result<(), E> {
|
||||||
match try!(self.expect_token()) {
|
match try!(self.expect_token()) {
|
||||||
End => Ok(()),
|
End => Ok(()),
|
||||||
_ => Err(self.syntax_error()),
|
_ => self.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -283,7 +283,7 @@ pub trait Deserializable<E, D: Deserializer<E>> {
|
|||||||
match d.next() {
|
match d.next() {
|
||||||
Some(Ok(token)) => Deserializable::deserialize_token(d, token),
|
Some(Ok(token)) => Deserializable::deserialize_token(d, token),
|
||||||
Some(Err(err)) => Err(err),
|
Some(Err(err)) => Err(err),
|
||||||
None => Err(d.end_of_stream_error()),
|
None => d.end_of_stream_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,7 +349,7 @@ macro_rules! deserialize_seq {
|
|||||||
$seq.push(v)
|
$seq.push(v)
|
||||||
}
|
}
|
||||||
Some(Err(err)) => { return Err(err); }
|
Some(Err(err)) => { return Err(err); }
|
||||||
None => { return Err(d.end_of_stream_error()); }
|
None => { return d.end_of_stream_error(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,7 +386,7 @@ macro_rules! deserialize_map {
|
|||||||
$seq.insert(k, v);
|
$seq.insert(k, v);
|
||||||
}
|
}
|
||||||
Some(Err(err)) => { return Err(err); }
|
Some(Err(err)) => { return Err(err); }
|
||||||
None => { return Err(d.end_of_stream_error()); }
|
None => { return d.end_of_stream_error(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,11 +463,9 @@ macro_rules! deserialize_tuple (
|
|||||||
$name
|
$name
|
||||||
},)*);
|
},)*);
|
||||||
|
|
||||||
match d.next() {
|
match try!(d.expect_token()) {
|
||||||
Some(Ok(End)) => Ok(result),
|
End => Ok(result),
|
||||||
Some(Ok(_)) => Err(d.syntax_error()),
|
_ => d.syntax_error(),
|
||||||
Some(Err(err)) => Err(err),
|
|
||||||
None => Err(d.end_of_stream_error()),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -509,7 +507,7 @@ impl<E, D: Deserializer<E>> Deserializable<E, D> for IgnoreTokens {
|
|||||||
Str(_) | String(_) => {
|
Str(_) | String(_) => {
|
||||||
let _: IgnoreTokens = try!(Deserializable::deserialize(d));
|
let _: IgnoreTokens = try!(Deserializable::deserialize(d));
|
||||||
}
|
}
|
||||||
_token => { return Err(d.syntax_error()); }
|
_token => { return d.syntax_error(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -548,7 +546,7 @@ impl<E, D: Deserializer<E>> Deserializable<E, D> for IgnoreTokens {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
End => Err(d.syntax_error()),
|
End => d.syntax_error(),
|
||||||
|
|
||||||
_ => Ok(IgnoreTokens),
|
_ => Ok(IgnoreTokens),
|
||||||
}
|
}
|
||||||
@ -608,7 +606,7 @@ impl GatherTokens {
|
|||||||
self.gather_map(d)
|
self.gather_map(d)
|
||||||
}
|
}
|
||||||
End => {
|
End => {
|
||||||
Err(d.syntax_error())
|
d.syntax_error()
|
||||||
}
|
}
|
||||||
token => {
|
token => {
|
||||||
self.tokens.push(token);
|
self.tokens.push(token);
|
||||||
@ -644,7 +642,7 @@ impl GatherTokens {
|
|||||||
self.tokens.push(token);
|
self.tokens.push(token);
|
||||||
try!(self.gather(d))
|
try!(self.gather(d))
|
||||||
}
|
}
|
||||||
_token => { return Err(d.syntax_error()); }
|
_token => { return d.syntax_error(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -789,14 +787,12 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Deserializer<Error> for TokenDeserializer {
|
impl Deserializer<Error> for TokenDeserializer {
|
||||||
#[inline]
|
fn end_of_stream_error<T>(&self) -> Result<T, Error> {
|
||||||
fn end_of_stream_error(&self) -> Error {
|
Err(EndOfStream)
|
||||||
EndOfStream
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
fn syntax_error<T>(&self) -> Result<T, Error> {
|
||||||
fn syntax_error(&self) -> Error {
|
Err(SyntaxError)
|
||||||
SyntaxError
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
32
json.rs
32
json.rs
@ -308,7 +308,7 @@ impl<E, D: de::Deserializer<E>> de::Deserializable<E, D> for Json {
|
|||||||
Ok(Object(object))
|
Ok(Object(object))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
de::End => Err(d.syntax_error()),
|
de::End => d.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -392,12 +392,12 @@ impl Iterator<Result<de::Token, ParserError>> for JsonDeserializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl de::Deserializer<ParserError> for JsonDeserializer {
|
impl de::Deserializer<ParserError> for JsonDeserializer {
|
||||||
fn end_of_stream_error(&self) -> ParserError {
|
fn end_of_stream_error<T>(&self) -> Result<T, ParserError> {
|
||||||
SyntaxError(EOFWhileParsingValue, 0, 0)
|
Err(SyntaxError(EOFWhileParsingValue, 0, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn syntax_error(&self) -> ParserError {
|
fn syntax_error<T>(&self) -> Result<T, ParserError> {
|
||||||
SyntaxError(InvalidSyntax, 0, 0)
|
Err(SyntaxError(InvalidSyntax, 0, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case treating options as a nullable value.
|
// Special case treating options as a nullable value.
|
||||||
@ -1842,12 +1842,12 @@ impl<T: Iterator<char>> Parser<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Iterator<char>> de::Deserializer<ParserError> for Parser<T> {
|
impl<T: Iterator<char>> de::Deserializer<ParserError> for Parser<T> {
|
||||||
fn end_of_stream_error(&self) -> ParserError {
|
fn end_of_stream_error<U>(&self) -> Result<U, ParserError> {
|
||||||
SyntaxError(EOFWhileParsingValue, self.line, self.col)
|
Err(SyntaxError(EOFWhileParsingValue, self.line, self.col))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn syntax_error(&self) -> ParserError {
|
fn syntax_error<U>(&self) -> Result<U, ParserError> {
|
||||||
SyntaxError(InvalidSyntax, self.line, self.col)
|
Err(SyntaxError(InvalidSyntax, self.line, self.col))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case treating options as a nullable value.
|
// Special case treating options as a nullable value.
|
||||||
@ -2599,7 +2599,7 @@ mod tests {
|
|||||||
|
|
||||||
Ok(Frog(x0, x1))
|
Ok(Frog(x0, x1))
|
||||||
}
|
}
|
||||||
_ => Err(d.syntax_error()),
|
_ => d.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2668,7 +2668,7 @@ mod tests {
|
|||||||
_ => { }
|
_ => { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => { return Err(d.syntax_error()); }
|
_ => { return d.syntax_error(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2676,10 +2676,10 @@ mod tests {
|
|||||||
(Some(a), Some(b), Some(c)) => {
|
(Some(a), Some(b), Some(c)) => {
|
||||||
Ok(Inner { a: a, b: b, c: c })
|
Ok(Inner { a: a, b: b, c: c })
|
||||||
}
|
}
|
||||||
_ => Err(d.syntax_error()),
|
_ => d.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(d.syntax_error()),
|
_ => d.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2728,7 +2728,7 @@ mod tests {
|
|||||||
_ => { }
|
_ => { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => { return Err(d.syntax_error()); }
|
_ => { return d.syntax_error(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2736,10 +2736,10 @@ mod tests {
|
|||||||
Some(inner) => {
|
Some(inner) => {
|
||||||
Ok(Outer { inner: inner })
|
Ok(Outer { inner: inner })
|
||||||
}
|
}
|
||||||
_ => Err(d.syntax_error()),
|
_ => d.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(d.syntax_error()),
|
_ => d.syntax_error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user