diff --git a/src/xml.rs b/src/xml.rs index 517e3df..0152a62 100644 --- a/src/xml.rs +++ b/src/xml.rs @@ -3235,13 +3235,14 @@ impl VTKFile { /// Parse an XML VTK file from the given reader. pub fn parse(reader: impl BufRead) -> Result { - let mut reader = quick_xml::Reader::from_reader(reader); - let config = reader.config_mut(); - config.expand_empty_elements = true; - config.check_end_names = true; - config.trim_text_start = true; - config.trim_text_end = false; - let mut de = de::Deserializer::from_custom_reader(reader); + // let mut reader = quick_xml::Reader::from_reader(reader); + // let config = reader.config_mut(); + // config.expand_empty_elements = true; + // config.check_end_names = true; + // config.trim_text_start = true; + // config.trim_text_end = false; + // let mut de = de::Deserializer::from_custom_reader(reader); + let mut de = de::Deserializer::from_reader(reader); Ok(VTKFile::deserialize(&mut de)?) } diff --git a/src/xml/se.rs b/src/xml/se.rs index 8c69e63..9e0fe12 100644 --- a/src/xml/se.rs +++ b/src/xml/se.rs @@ -5,13 +5,54 @@ use quick_xml::DeError; use serde::ser::Serialize; -/// Serialize struct into a `Write`r +#[cfg(not(feature = "binary"))] +struct ByteWriter(W) +where + W: std::io::Write; + +#[cfg(not(feature = "binary"))] +impl std::fmt::Write for ByteWriter { + fn write_str(&mut self, s: &str) -> std::fmt::Result { + self.0.write(s.as_bytes()).map_err(|_| std::fmt::Error)?; + std::fmt::Result::Ok(()) + } +} + +#[cfg(not(feature = "binary"))] +impl std::io::Write for ByteWriter { + fn write(&mut self, buf: &[u8]) -> std::io::Result { + self.0.write(buf) + } + + fn flush(&mut self) -> std::io::Result<()> { + self.0.flush() + } +} + +/// Serialize struct into an `io::Write`r +#[cfg(feature = "binary")] pub fn to_writer(writer: W, value: &S) -> Result<(), DeError> { let mut buf_writer = std::io::BufWriter::new(writer); let serializer = quick_xml::se::io::Serializer::new(&mut buf_writer); value.serialize(serializer) } +#[cfg(not(feature = "binary"))] +pub fn to_writer(writer: W, value: &S) -> Result<(), DeError> { + let mut buf_writer = ByteWriter(std::io::BufWriter::new(writer)); + let serializer = quick_xml::se::Serializer::new(&mut buf_writer); + value.serialize(serializer) +} + +/// Serialize struct into a `fmt::Write`r +pub fn to_fmt_writer( + mut writer: W, + value: &S, +) -> Result<(), DeError> { + let serializer = quick_xml::se::Serializer::new(&mut writer); + value.serialize(serializer) +} + /// Serialize struct into a `String` pub fn to_string(value: &S) -> Result { let mut s = String::new();