From 9bb65ea8fb85887368ed2c74aebd1c1547eeec83 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 24 May 2017 23:59:45 +0100 Subject: [PATCH] jingle_ibb: Simplify parsing and remove clones. --- src/jingle_ibb.rs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/jingle_ibb.rs b/src/jingle_ibb.rs index d89df221..6f789d3e 100644 --- a/src/jingle_ibb.rs +++ b/src/jingle_ibb.rs @@ -25,21 +25,17 @@ impl TryFrom for Transport { type Error = Error; fn try_from(elem: Element) -> Result { - if elem.is("transport", ns::JINGLE_IBB) { - for _ in elem.children() { - return Err(Error::ParseError("Unknown child in JingleIBB element.")); - } - let block_size = get_attr!(elem, "block-size", required); - let sid = get_attr!(elem, "sid", required); - let stanza = get_attr!(elem, "stanza", default); - Ok(Transport { - block_size: block_size, - sid: sid, - stanza: stanza - }) - } else { - Err(Error::ParseError("This is not an JingleIBB element.")) + if !elem.is("transport", ns::JINGLE_IBB) { + return Err(Error::ParseError("This is not an JingleIBB element.")) } + for _ in elem.children() { + return Err(Error::ParseError("Unknown child in JingleIBB element.")); + } + Ok(Transport { + block_size: get_attr!(elem, "block-size", required), + sid: get_attr!(elem, "sid", required), + stanza: get_attr!(elem, "stanza", default), + }) } } @@ -48,8 +44,8 @@ impl Into for Transport { Element::builder("transport") .ns(ns::JINGLE_IBB) .attr("block-size", format!("{}", self.block_size)) - .attr("sid", self.sid.clone()) - .attr("stanza", self.stanza.clone()) + .attr("sid", self.sid) + .attr("stanza", self.stanza) .build() } }