diff --git a/xso/src/lib.rs b/xso/src/lib.rs index 9df1c5548d6638387f6639f82a5950808d152d37..808435e699d9ca6f54eae3a8539b4eded1817b8c 100644 --- a/xso/src/lib.rs +++ b/xso/src/lib.rs @@ -27,6 +27,8 @@ use of this library in parsing XML streams like specified in RFC 6120. extern crate alloc; #[cfg(feature = "std")] extern crate std; +#[cfg(feature = "std")] +use std::io; pub mod asxml; pub mod error; @@ -454,7 +456,7 @@ pub fn try_from_element( } #[cfg(feature = "std")] -fn map_nonio_error(r: Result) -> Result { +fn map_nonio_error(r: Result) -> Result { match r { Ok(v) => Ok(v), Err(e) => match e.downcast::() { @@ -465,7 +467,7 @@ fn map_nonio_error(r: Result) -> Result( +fn read_start_event( r: &mut rxml::Reader, ) -> Result<(rxml::QName, rxml::AttrMap), self::error::Error> { for ev in r { @@ -506,23 +508,23 @@ pub fn from_bytes(mut buf: &[u8]) -> Result { } #[cfg(feature = "std")] -fn read_start_event_io( +fn read_start_event_io( r: &mut rxml::Reader, -) -> std::io::Result<(rxml::QName, rxml::AttrMap)> { +) -> io::Result<(rxml::QName, rxml::AttrMap)> { for ev in r { match ev? { rxml::Event::XmlDeclaration(_, rxml::XmlVersion::V1_0) => (), rxml::Event::StartElement(_, name, attrs) => return Ok((name, attrs)), _ => { - return Err(std::io::Error::new( - std::io::ErrorKind::InvalidData, + return Err(io::Error::new( + io::ErrorKind::InvalidData, self::error::Error::Other("Unexpected event at start of document"), )) } } } - Err(std::io::Error::new( - std::io::ErrorKind::InvalidData, + Err(io::Error::new( + io::ErrorKind::InvalidData, self::error::Error::XmlError(rxml::Error::InvalidEof(Some( rxml::error::ErrorContext::DocumentBegin, ))), @@ -531,29 +533,29 @@ fn read_start_event_io( /// Attempt to parse a type implementing [`FromXml`] from a reader. #[cfg(feature = "std")] -pub fn from_reader(r: R) -> std::io::Result { +pub fn from_reader(r: R) -> io::Result { let mut reader = rxml::Reader::new(r); let (name, attrs) = read_start_event_io(&mut reader)?; let mut builder = match T::from_events(name, attrs) { Ok(v) => v, Err(self::error::FromEventsError::Mismatch { .. }) => { return Err(self::error::Error::TypeMismatch) - .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e)) + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) } Err(self::error::FromEventsError::Invalid(e)) => { - return Err(e).map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e)) + return Err(e).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) } }; for ev in reader { if let Some(v) = builder .feed(ev?) - .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))? + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))? { return Ok(v); } } - Err(std::io::Error::new( - std::io::ErrorKind::UnexpectedEof, + Err(io::Error::new( + io::ErrorKind::UnexpectedEof, self::error::Error::XmlError(rxml::Error::InvalidEof(None)), )) }