From 41e1cf2654d34e78722a52f73ae6c42cad69f46b Mon Sep 17 00:00:00 2001 From: lumi Date: Mon, 20 Feb 2017 02:04:45 +0100 Subject: [PATCH] added has_child, fixed some warnings --- src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 063d0b9..0292bbe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ pub mod attribute; use std::io::prelude::*; -use std::convert::{From, AsRef}; +use std::convert::AsRef; use std::iter::Iterator; @@ -119,7 +119,7 @@ impl Element { namespace.get(NS_NO_PREFIX) }.map(|s| s.to_owned()); let mut root = Element::new(name.local_name, ns, attributes); - root.from_reader_inner(reader); + root.from_reader_inner(reader)?; return Ok(root); }, ReaderEvent::EndDocument => { @@ -146,7 +146,7 @@ impl Element { }.map(|s| s.to_owned()); let elem = Element::new(name.local_name, ns, attributes); let elem_ref = self.append_child(elem); - elem_ref.from_reader_inner(reader); + elem_ref.from_reader_inner(reader)?; }, ReaderEvent::EndElement { .. } => { // TODO: may want to check whether we're closing the correct element @@ -256,6 +256,9 @@ impl Element { None } + pub fn has_child, NS: AsRef>(&self, name: N, namespace: NS) -> bool { + self.get_child(name, namespace).is_some() + } } pub struct Children<'a> {