Detailed changes
@@ -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()
}
}
@@ -46,9 +46,9 @@ impl IntoAttributeValue for DateTime {
}
}
-impl Into<Node> for DateTime {
- fn into(self) -> Node {
- Node::Text(self.0.to_rfc3339())
+impl From<DateTime> for Node {
+ fn from(date: DateTime) -> Node {
+ Node::Text(date.0.to_rfc3339())
}
}
@@ -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.
@@ -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.
@@ -95,11 +95,7 @@ impl IqResultPayload for Join {}
impl Join {
/// Create a new Join element.
pub fn from_nick_and_nodes<N: Into<String>>(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.
@@ -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<Node> for Show {
- fn into(self) -> Node {
+impl From<Show> 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()
}
}
@@ -189,7 +189,7 @@ impl TryFrom<Element> 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."))
}
}
@@ -164,7 +164,7 @@ impl TryFrom<Element> 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."))
}
}
@@ -495,7 +495,7 @@ impl TryFrom<Element> 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."))
}
}
@@ -71,11 +71,7 @@ impl TryFrom<Element> 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::<Vec<_>>();
let key = part.pop().unwrap();