From 67442bfa0b0fd7874406e9080de398e486411870 Mon Sep 17 00:00:00 2001 From: xmppftw Date: Thu, 19 Dec 2024 20:27:33 +0100 Subject: [PATCH] minidom: Replace std::io calls with use std::io --- minidom/src/element.rs | 32 ++++++++++++++++---------------- minidom/src/error.rs | 2 +- minidom/src/node.rs | 4 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/minidom/src/element.rs b/minidom/src/element.rs index f67d7fc6..290fdc18 100644 --- a/minidom/src/element.rs +++ b/minidom/src/element.rs @@ -27,12 +27,12 @@ use alloc::{ use core::slice; use core::str::FromStr; -use std::io::{self, BufRead, Write}; +use std::io; use rxml::writer::{Encoder, Item, TrackNamespace}; use rxml::{Namespace as RxmlNamespace, RawReader, XmlVersion}; -fn encode_and_write( +fn encode_and_write( item: Item<'_>, enc: &mut Encoder, mut w: W, @@ -44,14 +44,14 @@ fn encode_and_write( Ok(()) } -/// Wrapper around a [`std::io::Write`] and an [`rxml::writer::Encoder`], to +/// Wrapper around a [`io::Write`] and an [`rxml::writer::Encoder`], to /// provide a simple function to write an rxml Item to a writer. pub struct CustomItemWriter { writer: W, encoder: Encoder, } -impl CustomItemWriter { +impl CustomItemWriter { pub(crate) fn new(writer: W) -> Self { Self { writer, @@ -60,7 +60,7 @@ impl CustomItemWriter { } } -impl CustomItemWriter { +impl CustomItemWriter { pub(crate) fn write(&mut self, item: Item<'_>) -> io::Result<()> { encode_and_write(item, &mut self.encoder, &mut self.writer) } @@ -333,8 +333,8 @@ impl Element { namespace.into().compare(self.namespace.as_ref()) } - /// Parse a document from a `BufRead`. - pub fn from_reader(reader: R) -> Result { + /// Parse a document from a `io::BufRead`. + pub fn from_reader(reader: R) -> Result { let mut tree_builder = TreeBuilder::new(); let mut driver = RawReader::new(reader); while let Some(event) = driver.read()? { @@ -347,10 +347,10 @@ impl Element { Err(Error::EndOfDocument) } - /// Parse a document from a `BufRead`, allowing Prefixes to be specified. Useful to provide + /// Parse a document from a `io::BufRead`, allowing Prefixes to be specified. Useful to provide /// knowledge of namespaces that would have been declared on parent elements not present in the /// reader. - pub fn from_reader_with_prefixes>( + pub fn from_reader_with_prefixes>( reader: R, prefixes: P, ) -> Result { @@ -366,23 +366,23 @@ impl Element { Err(Error::EndOfDocument) } - /// Output a document to a `Writer`. - pub fn write_to(&self, writer: &mut W) -> Result<()> { + /// Output a document to a `io::Writer`. + pub fn write_to(&self, writer: &mut W) -> Result<()> { self.to_writer(&mut ItemWriter::new(writer)) } - /// Output a document to a `Writer`. - pub fn write_to_decl(&self, writer: &mut W) -> Result<()> { + /// Output a document to a `io::Writer`. + pub fn write_to_decl(&self, writer: &mut W) -> Result<()> { self.to_writer_decl(&mut ItemWriter::new(writer)) } /// Output the document to an `ItemWriter` - pub fn to_writer(&self, writer: &mut ItemWriter) -> Result<()> { + pub fn to_writer(&self, writer: &mut ItemWriter) -> Result<()> { self.write_to_inner(writer) } /// Output the document to an `ItemWriter` - pub fn to_writer_decl(&self, writer: &mut ItemWriter) -> Result<()> { + pub fn to_writer_decl(&self, writer: &mut ItemWriter) -> Result<()> { writer .write(Item::XmlDeclaration(XmlVersion::V1_0)) .unwrap(); // TODO: error return @@ -390,7 +390,7 @@ impl Element { } /// Like `write_to()` but without the `` prelude - pub fn write_to_inner(&self, writer: &mut ItemWriter) -> Result<()> { + pub fn write_to_inner(&self, writer: &mut ItemWriter) -> Result<()> { for (prefix, namespace) in self.prefixes.declared_prefixes() { assert!(writer.encoder.ns_tracker_mut().declare_fixed( prefix.as_ref().map(|x| (&**x).try_into()).transpose()?, diff --git a/minidom/src/error.rs b/minidom/src/error.rs index d3cab837..8b15794b 100644 --- a/minidom/src/error.rs +++ b/minidom/src/error.rs @@ -24,7 +24,7 @@ pub enum Error { /// I/O error from accessing the source or destination. /// /// Even though the [`rxml`] crate emits its errors through - /// [`std::io::Error`] when using it with [`BufRead`][`std::io::BufRead`], + /// [`io::Error`] when using it with [`BufRead`][`io::BufRead`], /// any rxml errors will still be reported through the /// [`XmlError`][`Self::XmlError`] variant. Io(io::Error), diff --git a/minidom/src/node.rs b/minidom/src/node.rs index 2e1e9a54..c5374cf6 100644 --- a/minidom/src/node.rs +++ b/minidom/src/node.rs @@ -13,7 +13,7 @@ use crate::error::Result; use rxml::writer::Item; -use std::io::Write; +use std::io; /// A node in an element tree. #[derive(Clone, Debug, Eq)] @@ -158,7 +158,7 @@ impl Node { } #[doc(hidden)] - pub(crate) fn write_to_inner(&self, writer: &mut ItemWriter) -> Result<()> { + pub(crate) fn write_to_inner(&self, writer: &mut ItemWriter) -> Result<()> { match self { Node::Element(elmt) => elmt.write_to_inner(writer)?, Node::Text(s) => {