From 26d39b3a1517db4bc2d5891fcda9f4985ce08fd1 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 9 May 2017 11:22:18 +0200 Subject: [PATCH 1/2] Allow extracting the location of the error --- src/de.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/de.rs b/src/de.rs index 223d492..75129ed 100644 --- a/src/de.rs +++ b/src/de.rs @@ -1063,6 +1063,11 @@ impl<'a> Deserializer<'a> { } impl Error { + /// Produces a (line, column) pair of the position of the error if available + pub fn line_col(&self) -> Option<(usize, usize)> { + self.inner.line.map(|line| (line, self.inner.col)) + } + fn from_kind(kind: ErrorKind) -> Error { Error { inner: Box::new(ErrorInner { From 80ed3e7a7b0c25ec280e6b28a8e17635594d47dd Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 9 May 2017 17:08:26 +0200 Subject: [PATCH 2/2] Document that line/col indices are 0 based --- src/de.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/de.rs b/src/de.rs index 75129ed..bd73649 100644 --- a/src/de.rs +++ b/src/de.rs @@ -1064,6 +1064,8 @@ impl<'a> Deserializer<'a> { impl Error { /// Produces a (line, column) pair of the position of the error if available + /// + /// All indexes are 0-based. pub fn line_col(&self) -> Option<(usize, usize)> { self.inner.line.map(|line| (line, self.inner.col)) }