Merge branch 'clippy' into 'master'
fix clippy warnings See merge request lumi/minidom-rs!20
This commit is contained in:
commit
e8c1967b01
2 changed files with 16 additions and 16 deletions
|
@ -2,7 +2,7 @@ extern crate minidom;
|
||||||
|
|
||||||
use minidom::Element;
|
use minidom::Element;
|
||||||
|
|
||||||
const DATA: &'static str = r#"<articles xmlns="article">
|
const DATA: &str = r#"<articles xmlns="article">
|
||||||
<article>
|
<article>
|
||||||
<title>10 Terrible Bugs You Would NEVER Believe Happened</title>
|
<title>10 Terrible Bugs You Would NEVER Believe Happened</title>
|
||||||
<body>
|
<body>
|
||||||
|
@ -17,7 +17,7 @@ const DATA: &'static str = r#"<articles xmlns="article">
|
||||||
</article>
|
</article>
|
||||||
</articles>"#;
|
</articles>"#;
|
||||||
|
|
||||||
const ARTICLE_NS: &'static str = "article";
|
const ARTICLE_NS: &str = "article";
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Article {
|
pub struct Article {
|
||||||
|
|
|
@ -290,7 +290,7 @@ impl Element {
|
||||||
let e = reader.read_event(&mut buf)?;
|
let e = reader.read_event(&mut buf)?;
|
||||||
match e {
|
match e {
|
||||||
Event::Empty(ref e) | Event::Start(ref e) => {
|
Event::Empty(ref e) | Event::Start(ref e) => {
|
||||||
break build_element(&reader, e)?;
|
break build_element(reader, e)?;
|
||||||
},
|
},
|
||||||
Event::Eof => {
|
Event::Eof => {
|
||||||
bail!(ErrorKind::EndOfDocument);
|
bail!(ErrorKind::EndOfDocument);
|
||||||
|
@ -304,12 +304,12 @@ impl Element {
|
||||||
loop {
|
loop {
|
||||||
match reader.read_event(&mut buf)? {
|
match reader.read_event(&mut buf)? {
|
||||||
Event::Empty(ref e) => {
|
Event::Empty(ref e) => {
|
||||||
let elem = build_element(&reader, e)?;
|
let elem = build_element(reader, e)?;
|
||||||
// Since there is no Event::End after, directly append it to the current node
|
// Since there is no Event::End after, directly append it to the current node
|
||||||
stack.last_mut().unwrap().append_child(elem);
|
stack.last_mut().unwrap().append_child(elem);
|
||||||
},
|
},
|
||||||
Event::Start(ref e) => {
|
Event::Start(ref e) => {
|
||||||
let elem = build_element(&reader, e)?;
|
let elem = build_element(reader, e)?;
|
||||||
stack.push(elem);
|
stack.push(elem);
|
||||||
},
|
},
|
||||||
Event::End(ref e) => {
|
Event::End(ref e) => {
|
||||||
|
@ -348,20 +348,20 @@ 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 W) -> Result<()> {
|
pub fn write_to_inner<W: Write>(&self, writer: &mut W) -> Result<()> {
|
||||||
let name = match &self.prefix {
|
let name = match self.prefix {
|
||||||
&None => Cow::Borrowed(&self.name),
|
None => Cow::Borrowed(&self.name),
|
||||||
&Some(ref prefix) => Cow::Owned(format!("{}:{}", prefix, self.name)),
|
Some(ref prefix) => Cow::Owned(format!("{}:{}", prefix, self.name)),
|
||||||
};
|
};
|
||||||
write!(writer, "<{}", name)?;
|
write!(writer, "<{}", name)?;
|
||||||
|
|
||||||
for (prefix, ns) in self.namespaces.declared_ns() {
|
for (prefix, ns) in self.namespaces.declared_ns() {
|
||||||
match prefix {
|
match *prefix {
|
||||||
&None => {
|
None => {
|
||||||
write!(writer, " xmlns=\"")?;
|
write!(writer, " xmlns=\"")?;
|
||||||
write_escaped(writer, ns)?;
|
write_escaped(writer, ns)?;
|
||||||
write!(writer, "\"")?;
|
write!(writer, "\"")?;
|
||||||
},
|
},
|
||||||
&Some(ref prefix) => {
|
Some(ref prefix) => {
|
||||||
write!(writer, " xmlns:{}=\"", prefix)?;
|
write!(writer, " xmlns:{}=\"", prefix)?;
|
||||||
write_escaped(writer, ns)?;
|
write_escaped(writer, ns)?;
|
||||||
write!(writer, "\"")?;
|
write!(writer, "\"")?;
|
||||||
|
@ -496,7 +496,7 @@ impl Element {
|
||||||
/// assert_eq!(child.name(), "new");
|
/// assert_eq!(child.name(), "new");
|
||||||
/// ```
|
/// ```
|
||||||
pub fn append_child(&mut self, child: Element) -> &mut Element {
|
pub fn append_child(&mut self, child: Element) -> &mut Element {
|
||||||
child.namespaces.set_parent(self.namespaces.clone());
|
child.namespaces.set_parent(Rc::clone(&self.namespaces));
|
||||||
|
|
||||||
self.children.push(Node::Element(child));
|
self.children.push(Node::Element(child));
|
||||||
if let Node::Element(ref mut cld) = *self.children.last_mut().unwrap() {
|
if let Node::Element(ref mut cld) = *self.children.last_mut().unwrap() {
|
||||||
|
@ -639,12 +639,12 @@ fn build_element<R: BufRead>(reader: &EventReader<R>, event: &BytesStart) -> Res
|
||||||
Ok((key, value))
|
Ok((key, value))
|
||||||
})
|
})
|
||||||
.filter(|o| {
|
.filter(|o| {
|
||||||
match o {
|
match *o {
|
||||||
&Ok((ref key, ref value)) if key == "xmlns" => {
|
Ok((ref key, ref value)) if key == "xmlns" => {
|
||||||
namespaces.insert(None, value.to_owned());
|
namespaces.insert(None, value.to_owned());
|
||||||
false
|
false
|
||||||
},
|
},
|
||||||
&Ok((ref key, ref value)) if key.starts_with("xmlns:") => {
|
Ok((ref key, ref value)) if key.starts_with("xmlns:") => {
|
||||||
namespaces.insert(Some(key[6..].to_owned()), value.to_owned());
|
namespaces.insert(Some(key[6..].to_owned()), value.to_owned());
|
||||||
false
|
false
|
||||||
},
|
},
|
||||||
|
@ -799,7 +799,7 @@ impl ElementBuilder {
|
||||||
// Propagate namespaces
|
// Propagate namespaces
|
||||||
for node in &element.children {
|
for node in &element.children {
|
||||||
if let Node::Element(ref e) = *node {
|
if let Node::Element(ref e) = *node {
|
||||||
e.namespaces.set_parent(element.namespaces.clone());
|
e.namespaces.set_parent(Rc::clone(&element.namespaces));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue