minidom: Replace std::io calls with use std::io

This commit is contained in:
xmppftw 2024-12-19 20:27:33 +01:00 committed by Emmanuel Gil Peyrot
parent c8d3c068e0
commit 67442bfa0b
3 changed files with 19 additions and 19 deletions

View file

@ -27,12 +27,12 @@ use alloc::{
use core::slice; use core::slice;
use core::str::FromStr; use core::str::FromStr;
use std::io::{self, BufRead, Write}; use std::io;
use rxml::writer::{Encoder, Item, TrackNamespace}; use rxml::writer::{Encoder, Item, TrackNamespace};
use rxml::{Namespace as RxmlNamespace, RawReader, XmlVersion}; use rxml::{Namespace as RxmlNamespace, RawReader, XmlVersion};
fn encode_and_write<W: Write, T: rxml::writer::TrackNamespace>( fn encode_and_write<W: io::Write, T: rxml::writer::TrackNamespace>(
item: Item<'_>, item: Item<'_>,
enc: &mut Encoder<T>, enc: &mut Encoder<T>,
mut w: W, mut w: W,
@ -44,14 +44,14 @@ fn encode_and_write<W: Write, T: rxml::writer::TrackNamespace>(
Ok(()) 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. /// provide a simple function to write an rxml Item to a writer.
pub struct CustomItemWriter<W, T> { pub struct CustomItemWriter<W, T> {
writer: W, writer: W,
encoder: Encoder<T>, encoder: Encoder<T>,
} }
impl<W: Write> CustomItemWriter<W, rxml::writer::SimpleNamespaces> { impl<W: io::Write> CustomItemWriter<W, rxml::writer::SimpleNamespaces> {
pub(crate) fn new(writer: W) -> Self { pub(crate) fn new(writer: W) -> Self {
Self { Self {
writer, writer,
@ -60,7 +60,7 @@ impl<W: Write> CustomItemWriter<W, rxml::writer::SimpleNamespaces> {
} }
} }
impl<W: Write, T: rxml::writer::TrackNamespace> CustomItemWriter<W, T> { impl<W: io::Write, T: rxml::writer::TrackNamespace> CustomItemWriter<W, T> {
pub(crate) fn write(&mut self, item: Item<'_>) -> io::Result<()> { pub(crate) fn write(&mut self, item: Item<'_>) -> io::Result<()> {
encode_and_write(item, &mut self.encoder, &mut self.writer) encode_and_write(item, &mut self.encoder, &mut self.writer)
} }
@ -333,8 +333,8 @@ impl Element {
namespace.into().compare(self.namespace.as_ref()) namespace.into().compare(self.namespace.as_ref())
} }
/// Parse a document from a `BufRead`. /// Parse a document from a `io::BufRead`.
pub fn from_reader<R: BufRead>(reader: R) -> Result<Element> { pub fn from_reader<R: io::BufRead>(reader: R) -> Result<Element> {
let mut tree_builder = TreeBuilder::new(); let mut tree_builder = TreeBuilder::new();
let mut driver = RawReader::new(reader); let mut driver = RawReader::new(reader);
while let Some(event) = driver.read()? { while let Some(event) = driver.read()? {
@ -347,10 +347,10 @@ impl Element {
Err(Error::EndOfDocument) 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 /// knowledge of namespaces that would have been declared on parent elements not present in the
/// reader. /// reader.
pub fn from_reader_with_prefixes<R: BufRead, P: Into<Prefixes>>( pub fn from_reader_with_prefixes<R: io::BufRead, P: Into<Prefixes>>(
reader: R, reader: R,
prefixes: P, prefixes: P,
) -> Result<Element> { ) -> Result<Element> {
@ -366,23 +366,23 @@ impl Element {
Err(Error::EndOfDocument) Err(Error::EndOfDocument)
} }
/// Output a document to a `Writer`. /// Output a document to a `io::Writer`.
pub fn write_to<W: Write>(&self, writer: &mut W) -> Result<()> { pub fn write_to<W: io::Write>(&self, writer: &mut W) -> Result<()> {
self.to_writer(&mut ItemWriter::new(writer)) self.to_writer(&mut ItemWriter::new(writer))
} }
/// Output a document to a `Writer`. /// Output a document to a `io::Writer`.
pub fn write_to_decl<W: Write>(&self, writer: &mut W) -> Result<()> { pub fn write_to_decl<W: io::Write>(&self, writer: &mut W) -> Result<()> {
self.to_writer_decl(&mut ItemWriter::new(writer)) self.to_writer_decl(&mut ItemWriter::new(writer))
} }
/// Output the document to an `ItemWriter` /// Output the document to an `ItemWriter`
pub fn to_writer<W: Write>(&self, writer: &mut ItemWriter<W>) -> Result<()> { pub fn to_writer<W: io::Write>(&self, writer: &mut ItemWriter<W>) -> Result<()> {
self.write_to_inner(writer) self.write_to_inner(writer)
} }
/// Output the document to an `ItemWriter` /// Output the document to an `ItemWriter`
pub fn to_writer_decl<W: Write>(&self, writer: &mut ItemWriter<W>) -> Result<()> { pub fn to_writer_decl<W: io::Write>(&self, writer: &mut ItemWriter<W>) -> Result<()> {
writer writer
.write(Item::XmlDeclaration(XmlVersion::V1_0)) .write(Item::XmlDeclaration(XmlVersion::V1_0))
.unwrap(); // TODO: error return .unwrap(); // TODO: error return
@ -390,7 +390,7 @@ impl Element {
} }
/// Like `write_to()` but without the `<?xml?>` prelude /// Like `write_to()` but without the `<?xml?>` prelude
pub fn write_to_inner<W: Write>(&self, writer: &mut ItemWriter<W>) -> Result<()> { pub fn write_to_inner<W: io::Write>(&self, writer: &mut ItemWriter<W>) -> Result<()> {
for (prefix, namespace) in self.prefixes.declared_prefixes() { for (prefix, namespace) in self.prefixes.declared_prefixes() {
assert!(writer.encoder.ns_tracker_mut().declare_fixed( assert!(writer.encoder.ns_tracker_mut().declare_fixed(
prefix.as_ref().map(|x| (&**x).try_into()).transpose()?, prefix.as_ref().map(|x| (&**x).try_into()).transpose()?,

View file

@ -24,7 +24,7 @@ pub enum Error {
/// I/O error from accessing the source or destination. /// I/O error from accessing the source or destination.
/// ///
/// Even though the [`rxml`] crate emits its errors through /// 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 /// any rxml errors will still be reported through the
/// [`XmlError`][`Self::XmlError`] variant. /// [`XmlError`][`Self::XmlError`] variant.
Io(io::Error), Io(io::Error),

View file

@ -13,7 +13,7 @@ use crate::error::Result;
use rxml::writer::Item; use rxml::writer::Item;
use std::io::Write; use std::io;
/// A node in an element tree. /// A node in an element tree.
#[derive(Clone, Debug, Eq)] #[derive(Clone, Debug, Eq)]
@ -158,7 +158,7 @@ impl Node {
} }
#[doc(hidden)] #[doc(hidden)]
pub(crate) fn write_to_inner<W: Write>(&self, writer: &mut ItemWriter<W>) -> Result<()> { pub(crate) fn write_to_inner<W: io::Write>(&self, writer: &mut ItemWriter<W>) -> Result<()> {
match self { match self {
Node::Element(elmt) => elmt.write_to_inner(writer)?, Node::Element(elmt) => elmt.write_to_inner(writer)?,
Node::Text(s) => { Node::Text(s) => {