|
3 | 3 | use crate::escape::EscapeError; |
4 | 4 | use crate::events::attributes::AttrError; |
5 | 5 | use crate::utils::write_byte_string; |
| 6 | +use std::fmt; |
| 7 | +use std::io::Error as IoError; |
6 | 8 | use std::str::Utf8Error; |
7 | 9 | use std::string::FromUtf8Error; |
8 | 10 |
|
9 | 11 | /// The error type used by this crate. |
10 | 12 | #[derive(Debug)] |
11 | 13 | pub enum Error { |
12 | 14 | /// IO error |
13 | | - Io(::std::io::Error), |
| 15 | + Io(IoError), |
14 | 16 | /// Input decoding error. If `encoding` feature is disabled, contains `None`, |
15 | 17 | /// otherwise contains the UTF-8 decoding error |
16 | 18 | NonDecodable(Option<Utf8Error>), |
@@ -39,10 +41,10 @@ pub enum Error { |
39 | 41 | UnknownPrefix(Vec<u8>), |
40 | 42 | } |
41 | 43 |
|
42 | | -impl From<::std::io::Error> for Error { |
| 44 | +impl From<IoError> for Error { |
43 | 45 | /// Creates a new `Error::Io` from the given error |
44 | 46 | #[inline] |
45 | | - fn from(error: ::std::io::Error) -> Error { |
| 47 | + fn from(error: IoError) -> Error { |
46 | 48 | Error::Io(error) |
47 | 49 | } |
48 | 50 | } |
@@ -81,8 +83,8 @@ impl From<AttrError> for Error { |
81 | 83 | /// A specialized `Result` type where the error is hard-wired to [`Error`]. |
82 | 84 | pub type Result<T> = std::result::Result<T, Error>; |
83 | 85 |
|
84 | | -impl std::fmt::Display for Error { |
85 | | - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
| 86 | +impl fmt::Display for Error { |
| 87 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
86 | 88 | match self { |
87 | 89 | Error::Io(e) => write!(f, "I/O error: {}", e), |
88 | 90 | Error::NonDecodable(None) => write!(f, "Malformed input, decoding impossible"), |
@@ -132,7 +134,7 @@ pub mod serialize { |
132 | 134 |
|
133 | 135 | use super::*; |
134 | 136 | use crate::utils::write_byte_string; |
135 | | - use std::fmt; |
| 137 | + use std::borrow::Cow; |
136 | 138 | #[cfg(feature = "overlapped-lists")] |
137 | 139 | use std::num::NonZeroUsize; |
138 | 140 | use std::num::{ParseFloatError, ParseIntError}; |
@@ -186,7 +188,7 @@ pub mod serialize { |
186 | 188 | /// An attempt to deserialize to a type, that is not supported by the XML |
187 | 189 | /// store at current position, for example, attempt to deserialize `struct` |
188 | 190 | /// from attribute or attempt to deserialize binary data. |
189 | | - Unsupported(&'static str), |
| 191 | + Unsupported(Cow<'static, str>), |
190 | 192 | /// Too many events were skipped while deserializing a sequence, event limit |
191 | 193 | /// exceeded. The limit was provided as an argument |
192 | 194 | #[cfg(feature = "overlapped-lists")] |
@@ -214,7 +216,7 @@ pub mod serialize { |
214 | 216 | } |
215 | 217 | DeError::UnexpectedEof => write!(f, "Unexpected `Event::Eof`"), |
216 | 218 | DeError::ExpectedStart => write!(f, "Expecting `Event::Start`"), |
217 | | - DeError::Unsupported(s) => write!(f, "Unsupported operation {}", s), |
| 219 | + DeError::Unsupported(s) => write!(f, "Unsupported operation: {}", s), |
218 | 220 | #[cfg(feature = "overlapped-lists")] |
219 | 221 | DeError::TooManyEvents(s) => write!(f, "Deserializer buffers {} events, limit exceeded", s), |
220 | 222 | } |
@@ -292,4 +294,11 @@ pub mod serialize { |
292 | 294 | Self::InvalidFloat(e) |
293 | 295 | } |
294 | 296 | } |
| 297 | + |
| 298 | + impl From<fmt::Error> for DeError { |
| 299 | + #[inline] |
| 300 | + fn from(e: fmt::Error) -> Self { |
| 301 | + Self::Custom(e.to_string()) |
| 302 | + } |
| 303 | + } |
295 | 304 | } |
0 commit comments