Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Commit f9f4ba8

Browse files
committed
implement Error for ParserError
1 parent 9465721 commit f9f4ba8

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/json.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,15 @@ use self::DecoderError::*;
202202
use self::ParserState::*;
203203
use self::InternalStackElement::*;
204204

205-
use std;
206205
use std::collections::{HashMap, BTreeMap};
207-
use std::{char, f64, fmt, io, num, str};
206+
use std::error::Error as StdError;
208207
use std::mem::{swap, transmute};
209208
use std::num::{Float, Int};
209+
use std::ops::Index;
210210
use std::str::{FromStr};
211211
use std::string;
212-
use std::ops::Index;
212+
use std::{char, f64, fmt, io, num, str};
213+
use std;
213214
use unicode::str as unicode_str;
214215
use unicode::str::Utf16Item;
215216

@@ -331,9 +332,20 @@ fn io_error_to_error(io: io::IoError) -> ParserError {
331332
IoError(io.kind, io.desc)
332333
}
333334

334-
impl std::error::Error for DecoderError {
335+
impl StdError for DecoderError {
335336
fn description(&self) -> &str { "decoder error" }
336337
fn detail(&self) -> Option<std::string::String> { Some(format!("{:?}", self)) }
338+
fn cause(&self) -> Option<&StdError> {
339+
match *self {
340+
DecoderError::ParseError(ref e) => Some(e as &StdError),
341+
_ => None,
342+
}
343+
}
344+
}
345+
346+
impl StdError for ParserError {
347+
fn description(&self) -> &str { "failed to parse json" }
348+
fn detail(&self) -> Option<std::string::String> { Some(format!("{:?}", self)) }
337349
}
338350

339351
pub type EncodeResult = Result<(), fmt::Error>;

0 commit comments

Comments
 (0)