Update rxml to 0.11.0
This commit is contained in:
parent
2097b9685f
commit
84de007640
6 changed files with 19 additions and 18 deletions
|
@ -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"] }
|
||||
|
|
|
@ -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<R: BufRead>(reader: R) -> Result<Element> {
|
||||
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<Element> {
|
||||
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() {
|
||||
|
|
|
@ -71,5 +71,11 @@ impl From<rxml::error::XmlError> for Error {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<rxml::strings::Error> for Error {
|
||||
fn from(err: rxml::strings::Error) -> Error {
|
||||
rxml::error::XmlError::from(err).into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Our simplified Result type.
|
||||
pub type Result<T> = ::std::result::Result<T, Error>;
|
||||
|
|
|
@ -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()))?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -96,7 +96,7 @@ impl Decoder for XMPPCodec {
|
|||
|
||||
fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<Self::Item>, 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,
|
||||
|
|
Loading…
Reference in a new issue