From 84de00764053a0ea0a800303e6c81fa32d5b8778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=A4fer?= Date: Thu, 23 May 2024 18:12:09 +0200 Subject: [PATCH] Update rxml to 0.11.0 --- minidom/Cargo.toml | 2 +- minidom/src/element.rs | 23 +++++++++-------------- minidom/src/error.rs | 6 ++++++ minidom/src/node.rs | 2 +- tokio-xmpp/Cargo.toml | 2 +- tokio-xmpp/src/xmpp_codec.rs | 2 +- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/minidom/Cargo.toml b/minidom/Cargo.toml index 97081fa1..063e66d1 100644 --- a/minidom/Cargo.toml +++ b/minidom/Cargo.toml @@ -21,4 +21,4 @@ edition = "2021" gitlab = { repository = "xmpp-rs/xmpp-rs" } [dependencies] -rxml = { version = "0.10.1", default-features = false, features = ["sync", "smartstring"] } +rxml = { version = "0.11.0", default-features = false, features = ["compact_str"] } diff --git a/minidom/src/element.rs b/minidom/src/element.rs index 6d1bdfa1..b161a996 100644 --- a/minidom/src/element.rs +++ b/minidom/src/element.rs @@ -21,13 +21,12 @@ use crate::tree_builder::TreeBuilder; use std::collections::{btree_map, BTreeMap}; use std::io::{BufRead, Write}; -use std::sync::Arc; use std::borrow::Cow; use std::str; use rxml::writer::{Encoder, Item, TrackNamespace}; -use rxml::{RawParser, Reader, XmlVersion}; +use rxml::{Namespace as RxmlNamespace, RawReader, XmlVersion}; use std::str::FromStr; @@ -337,7 +336,7 @@ impl Element { /// Parse a document from a `BufRead`. pub fn from_reader(reader: R) -> Result { let mut tree_builder = TreeBuilder::new(); - let mut driver = Reader::<_, RawParser>::new(reader); + let mut driver = RawReader::new(reader); while let Some(event) = driver.read()? { tree_builder.process_event(event)?; @@ -356,7 +355,7 @@ impl Element { prefixes: P, ) -> Result { let mut tree_builder = TreeBuilder::new().with_prefixes_stack(vec![prefixes.into()]); - let mut driver = Reader::<_, RawParser>::new(reader); + let mut driver = RawReader::new(reader); while let Some(event) = driver.read()? { tree_builder.process_event(event)?; @@ -395,16 +394,12 @@ impl Element { 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()?, - Some(Arc::new(namespace.clone().try_into()?)) + namespace.clone().into(), )); } - let namespace = if self.namespace.is_empty() { - None - } else { - Some(Arc::new(self.namespace.clone().try_into()?)) - }; - writer.write(Item::ElementHeadStart(namespace, (*self.name).try_into()?))?; + let namespace: RxmlNamespace = self.namespace.clone().into(); + writer.write(Item::ElementHeadStart(&namespace, (*self.name).try_into()?))?; for (key, value) in self.attributes.iter() { let (prefix, name) = <&rxml::NameStr>::try_from(&**key) @@ -413,12 +408,12 @@ impl Element { .unwrap(); let namespace = match prefix { Some(prefix) => match writer.encoder.ns_tracker().lookup_prefix(Some(prefix)) { - Ok(v) => Some(v), + Ok(v) => v, Err(rxml::writer::PrefixError::Undeclared) => return Err(Error::InvalidPrefix), }, - None => None, + None => RxmlNamespace::NONE, }; - writer.write(Item::Attribute(namespace, name, (&**value).try_into()?))?; + writer.write(Item::Attribute(&namespace, name, (&**value).into()))?; } if !self.children.is_empty() { diff --git a/minidom/src/error.rs b/minidom/src/error.rs index 408fcaff..694c766c 100644 --- a/minidom/src/error.rs +++ b/minidom/src/error.rs @@ -71,5 +71,11 @@ impl From for Error { } } +impl From for Error { + fn from(err: rxml::strings::Error) -> Error { + rxml::error::XmlError::from(err).into() + } +} + /// Our simplified Result type. pub type Result = ::std::result::Result; diff --git a/minidom/src/node.rs b/minidom/src/node.rs index 7486466c..5ef5dc24 100644 --- a/minidom/src/node.rs +++ b/minidom/src/node.rs @@ -162,7 +162,7 @@ impl Node { match *self { Node::Element(ref elmt) => elmt.write_to_inner(writer)?, Node::Text(ref s) => { - writer.write(Item::Text((&**s).try_into()?))?; + writer.write(Item::Text((&**s).into()))?; } } diff --git a/tokio-xmpp/Cargo.toml b/tokio-xmpp/Cargo.toml index 64063b46..223356ed 100644 --- a/tokio-xmpp/Cargo.toml +++ b/tokio-xmpp/Cargo.toml @@ -19,7 +19,7 @@ tokio = { version = "1", features = ["net", "rt", "rt-multi-thread", "macros"] } tokio-stream = { version = "0.1", features = [] } tokio-util = { version = "0.7", features = ["codec"] } webpki-roots = { version = "0.25", optional = true } -rxml = { version = "0.10.1", features = ["smartstring"] } +rxml = { version = "0.11.0", features = ["compact_str"] } rand = "^0.8" syntect = { version = "5", optional = true } # same repository dependencies diff --git a/tokio-xmpp/src/xmpp_codec.rs b/tokio-xmpp/src/xmpp_codec.rs index 1ac7e50a..baef066f 100644 --- a/tokio-xmpp/src/xmpp_codec.rs +++ b/tokio-xmpp/src/xmpp_codec.rs @@ -96,7 +96,7 @@ impl Decoder for XMPPCodec { fn decode(&mut self, buf: &mut BytesMut) -> Result, Self::Error> { loop { - let token = match self.driver.parse(buf, false) { + let token = match self.driver.parse_buf(buf, false) { Ok(Some(token)) => token, Ok(None) => break, Err(rxml::Error::IO(e)) if e.kind() == std::io::ErrorKind::WouldBlock => break,