aboutsummaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs39
1 files changed, 11 insertions, 28 deletions
diff --git a/src/error.rs b/src/error.rs
index 793ad3e..ae2a6d8 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,10 +1,9 @@
-use std::error::Error as StdError;
-use std::fmt;
-use std::io;
-use std::result;
+use std::{error::Error as StdError, fmt, io, result};
-use crate::byte_record::{ByteRecord, Position};
-use crate::deserializer::DeserializeError;
+use crate::{
+ byte_record::{ByteRecord, Position},
+ deserializer::DeserializeError,
+};
/// A type alias for `Result<T, csv::Error>`.
pub type Result<T> = result::Result<T, Error>;
@@ -134,19 +133,7 @@ impl From<Error> for io::Error {
}
}
-impl StdError for Error {
- fn source(&self) -> Option<&(dyn StdError + 'static)> {
- match *self.0 {
- ErrorKind::Io(ref err) => Some(err),
- ErrorKind::Utf8 { ref err, .. } => Some(err),
- ErrorKind::UnequalLengths { .. } => None,
- ErrorKind::Seek => None,
- ErrorKind::Serialize(_) => None,
- ErrorKind::Deserialize { ref err, .. } => Some(err),
- _ => unreachable!(),
- }
- }
-}
+impl StdError for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -227,8 +214,8 @@ pub struct FromUtf8Error {
impl FromUtf8Error {
/// Create a new FromUtf8Error.
- pub(crate) fn new(rec: ByteRecord, err: Utf8Error) -> FromUtf8Error {
- FromUtf8Error { record: rec, err: err }
+ pub(crate) fn new(record: ByteRecord, err: Utf8Error) -> FromUtf8Error {
+ FromUtf8Error { record, err }
}
/// Access the underlying `ByteRecord` that failed UTF-8 validation.
@@ -271,7 +258,7 @@ pub struct Utf8Error {
/// Create a new UTF-8 error.
pub fn new_utf8_error(field: usize, valid_up_to: usize) -> Utf8Error {
- Utf8Error { field: field, valid_up_to: valid_up_to }
+ Utf8Error { field, valid_up_to }
}
impl Utf8Error {
@@ -315,7 +302,7 @@ impl<W> IntoInnerError<W> {
/// (This is a visibility hack. It's public in this module, but not in the
/// crate.)
pub(crate) fn new(wtr: W, err: io::Error) -> IntoInnerError<W> {
- IntoInnerError { wtr: wtr, err: err }
+ IntoInnerError { wtr, err }
}
/// Returns the error which caused the call to `into_inner` to fail.
@@ -334,11 +321,7 @@ impl<W> IntoInnerError<W> {
}
}
-impl<W: std::any::Any> StdError for IntoInnerError<W> {
- fn source(&self) -> Option<&(dyn StdError + 'static)> {
- self.err.source()
- }
-}
+impl<W: std::any::Any> StdError for IntoInnerError<W> {}
impl<W> fmt::Display for IntoInnerError<W> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {