diff --git a/parsers/src/bookmarks2.rs b/parsers/src/bookmarks2.rs index bbccd40..76db15a 100644 --- a/parsers/src/bookmarks2.rs +++ b/parsers/src/bookmarks2.rs @@ -16,7 +16,7 @@ generate_attribute!( ); /// A conference bookmark. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct Conference { /// Whether a conference bookmark should be joined automatically. pub autojoin: Autojoin, @@ -37,13 +37,7 @@ pub struct Conference { impl Conference { /// Create a new conference. pub fn new() -> Conference { - Conference { - autojoin: Autojoin::False, - name: None, - nick: None, - password: None, - extensions: None, - } + Conference::default() } } diff --git a/parsers/src/date.rs b/parsers/src/date.rs index ee3080b..07d73bc 100644 --- a/parsers/src/date.rs +++ b/parsers/src/date.rs @@ -46,9 +46,9 @@ impl IntoAttributeValue for DateTime { } } -impl Into for DateTime { - fn into(self) -> Node { - Node::Text(self.0.to_rfc3339()) +impl From for Node { + fn from(date: DateTime) -> Node { + Node::Text(date.0.to_rfc3339()) } } diff --git a/parsers/src/jingle_ice_udp.rs b/parsers/src/jingle_ice_udp.rs index 6fb0e26..f3db3ae 100644 --- a/parsers/src/jingle_ice_udp.rs +++ b/parsers/src/jingle_ice_udp.rs @@ -9,6 +9,7 @@ use std::net::IpAddr; generate_element!( /// Wrapper element for an ICE-UDP transport. + #[derive(Default)] Transport, "transport", JINGLE_ICE_UDP, attributes: [ /// A Password as defined in ICE-CORE. @@ -29,12 +30,7 @@ generate_element!( impl Transport { /// Create a new ICE-UDP transport. pub fn new() -> Transport { - Transport { - pwd: None, - ufrag: None, - candidates: Vec::new(), - fingerprint: None, - } + Transport::default() } /// Add a candidate to this transport. diff --git a/parsers/src/jingle_raw_udp.rs b/parsers/src/jingle_raw_udp.rs index 9197980..d40bb68 100644 --- a/parsers/src/jingle_raw_udp.rs +++ b/parsers/src/jingle_raw_udp.rs @@ -9,6 +9,7 @@ use std::net::IpAddr; generate_element!( /// Wrapper element for an raw UDP transport. + #[derive(Default)] Transport, "transport", JINGLE_RAW_UDP, children: [ /// List of candidates for this raw UDP session. @@ -19,9 +20,7 @@ generate_element!( impl Transport { /// Create a new ICE-UDP transport. pub fn new() -> Transport { - Transport { - candidates: Vec::new(), - } + Transport::default() } /// Add a candidate to this transport. diff --git a/parsers/src/mix.rs b/parsers/src/mix.rs index 7043f8a..2ca49f4 100644 --- a/parsers/src/mix.rs +++ b/parsers/src/mix.rs @@ -95,11 +95,7 @@ impl IqResultPayload for Join {} impl Join { /// Create a new Join element. pub fn from_nick_and_nodes>(nick: N, nodes: &[&str]) -> Join { - let subscribes = nodes - .into_iter() - .cloned() - .map(|n| Subscribe::new(n)) - .collect(); + let subscribes = nodes.iter().cloned().map(Subscribe::new).collect(); Join { id: None, nick: nick.into(), @@ -136,11 +132,7 @@ impl IqResultPayload for UpdateSubscription {} impl UpdateSubscription { /// Create a new UpdateSubscription element. pub fn from_nodes(nodes: &[&str]) -> UpdateSubscription { - let subscribes = nodes - .into_iter() - .cloned() - .map(|n| Subscribe::new(n)) - .collect(); + let subscribes = nodes.iter().cloned().map(Subscribe::new).collect(); UpdateSubscription { jid: None, subscribes, @@ -212,6 +204,7 @@ impl Mix { generate_element!( /// Create a new MIX channel. + #[derive(Default)] Create, "create", MIX_CORE, attributes: [ /// The requested channel identifier. @@ -225,7 +218,7 @@ impl IqResultPayload for Create {} impl Create { /// Create a new ad-hoc Create element. pub fn new() -> Create { - Create { channel: None } + Create::default() } /// Create a new Create element with a channel identifier. diff --git a/parsers/src/presence.rs b/parsers/src/presence.rs index 2d70714..31e6096 100644 --- a/parsers/src/presence.rs +++ b/parsers/src/presence.rs @@ -8,7 +8,7 @@ use crate::ns; use crate::util::error::Error; use jid::Jid; -use minidom::{Element, IntoAttributeValue, Node}; +use minidom::{Element, IntoAttributeValue}; use std::collections::BTreeMap; use std::convert::TryFrom; use std::str::FromStr; @@ -48,17 +48,16 @@ impl FromStr for Show { } } -impl Into for Show { - fn into(self) -> Node { +impl From for Element { + fn from(show: Show) -> Element { Element::builder("show", ns::DEFAULT_NS) - .append(match self { + .append(match show { Show::Away => "away", Show::Chat => "chat", Show::Dnd => "dnd", Show::Xa => "xa", }) .build() - .into() } } diff --git a/parsers/src/pubsub/event.rs b/parsers/src/pubsub/event.rs index 6ad2bc9..c0ab830 100644 --- a/parsers/src/pubsub/event.rs +++ b/parsers/src/pubsub/event.rs @@ -189,7 +189,7 @@ impl TryFrom for PubSubEvent { return Err(Error::ParseError("Unknown child in event element.")); } } - Ok(payload.ok_or(Error::ParseError("No payload in event element."))?) + payload.ok_or(Error::ParseError("No payload in event element.")) } } diff --git a/parsers/src/pubsub/owner.rs b/parsers/src/pubsub/owner.rs index a890523..6d94b2f 100644 --- a/parsers/src/pubsub/owner.rs +++ b/parsers/src/pubsub/owner.rs @@ -164,7 +164,7 @@ impl TryFrom for PubSubOwner { return Err(Error::ParseError("Unknown child in pubsub element.")); } } - Ok(payload.ok_or(Error::ParseError("No payload in pubsub element."))?) + payload.ok_or(Error::ParseError("No payload in pubsub element.")) } } diff --git a/parsers/src/pubsub/pubsub.rs b/parsers/src/pubsub/pubsub.rs index 1811a8d..19f16e0 100644 --- a/parsers/src/pubsub/pubsub.rs +++ b/parsers/src/pubsub/pubsub.rs @@ -495,7 +495,7 @@ impl TryFrom for PubSub { return Err(Error::ParseError("Unknown child in pubsub element.")); } } - Ok(payload.ok_or(Error::ParseError("No payload in pubsub element."))?) + payload.ok_or(Error::ParseError("No payload in pubsub element.")) } } diff --git a/parsers/src/xhtml.rs b/parsers/src/xhtml.rs index fd0312f..2ce1892 100644 --- a/parsers/src/xhtml.rs +++ b/parsers/src/xhtml.rs @@ -71,11 +71,7 @@ impl TryFrom for XhtmlIm { for child in elem.children() { if child.is("body", ns::XHTML) { let child = child.clone(); - let lang = match child.attr("xml:lang") { - Some(lang) => lang, - None => "", - } - .to_string(); + let lang = child.attr("xml:lang").unwrap_or("").to_string(); let body = Body::try_from(child)?; match bodies.insert(lang, body) { None => (), @@ -488,9 +484,9 @@ fn parse_css(style: Option<&str>) -> Css { let mut properties = vec![]; if let Some(style) = style { // TODO: make that parser a bit more resilient to things. - for part in style.split(";") { + for part in style.split(';') { let mut part = part - .splitn(2, ":") + .splitn(2, ':') .map(|a| a.to_string()) .collect::>(); let key = part.pop().unwrap();