From 637c3eadd71def30897de32ab748a531c6f3050d Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 21 Feb 2019 21:00:58 +0100 Subject: [PATCH] Fix clippy lints. --- src/bookmarks.rs | 6 ++---- src/caps.rs | 4 ++-- src/component.rs | 3 ++- src/data_forms.rs | 2 +- src/disco.rs | 4 ++-- src/ecaps2.rs | 2 +- src/iq.rs | 8 ++++---- src/jingle.rs | 8 ++++---- src/jingle_ft.rs | 12 ++---------- src/jingle_s5b.rs | 8 ++++---- src/message.rs | 18 +++++++++--------- src/muc/muc.rs | 16 ++++------------ src/muc/user.rs | 4 ++-- src/presence.rs | 2 +- src/pubsub/event.rs | 2 +- src/pubsub/mod.rs | 2 +- src/sasl.rs | 4 ++-- src/sm.rs | 6 ++---- src/stanza_error.rs | 10 +++++----- src/util/helpers.rs | 10 +++++----- 20 files changed, 56 insertions(+), 75 deletions(-) diff --git a/src/bookmarks.rs b/src/bookmarks.rs index 12f9570..273f770 100644 --- a/src/bookmarks.rs +++ b/src/bookmarks.rs @@ -49,6 +49,7 @@ generate_element!( generate_element!( /// Container element for multiple bookmarks. + #[derive(Default)] Storage, "storage", BOOKMARKS, children: [ /// Conferences the user has expressed an interest in. @@ -62,10 +63,7 @@ generate_element!( impl Storage { /// Create an empty bookmarks storage. pub fn new() -> Storage { - Storage { - conferences: Vec::new(), - urls: Vec::new(), - } + Storage::default() } } diff --git a/src/caps.rs b/src/caps.rs index 419e72c..a7948d1 100644 --- a/src/caps.rs +++ b/src/caps.rs @@ -54,7 +54,7 @@ impl TryFrom for Caps { Ok(Caps { ext: get_attr!(elem, "ext", optional), node: get_attr!(elem, "node", required), - hash: hash, + hash, }) } } @@ -202,7 +202,7 @@ pub fn hash_caps(data: &[u8], algo: Algo) -> Result { } Algo::Unknown(algo) => return Err(format!("Unknown algorithm: {}.", algo)), }, - algo: algo, + algo, }) } diff --git a/src/component.rs b/src/component.rs index 722495b..4ab78c5 100644 --- a/src/component.rs +++ b/src/component.rs @@ -10,6 +10,7 @@ use sha1::Sha1; generate_element!( /// The main authentication mechanism for components. + #[derive(Default)] Handshake, "handshake", COMPONENT, text: ( /// If Some, contains the hex-encoded SHA-1 of the concatenation of the @@ -25,7 +26,7 @@ generate_element!( impl Handshake { /// Creates a successful reply from a server. pub fn new() -> Handshake { - Handshake { data: None } + Handshake::default() } /// Creates an authentication request from the component. diff --git a/src/data_forms.rs b/src/data_forms.rs index 30dbd29..bce9413 100644 --- a/src/data_forms.rs +++ b/src/data_forms.rs @@ -222,7 +222,7 @@ impl TryFrom for DataForm { check_no_unknown_attributes!(elem, "x", ["type"]); let type_ = get_attr!(elem, "type", required); let mut form = DataForm { - type_: type_, + type_, form_type: None, title: None, instructions: None, diff --git a/src/disco.rs b/src/disco.rs index ee673b8..9f72cec 100644 --- a/src/disco.rs +++ b/src/disco.rs @@ -86,8 +86,8 @@ impl TryFrom for Identity { } Ok(Identity { - category: category, - type_: type_, + category, + type_, lang: get_attr!(elem, "xml:lang", optional), name: get_attr!(elem, "name", optional), }) diff --git a/src/ecaps2.rs b/src/ecaps2.rs index 846fa6d..ef3a593 100644 --- a/src/ecaps2.rs +++ b/src/ecaps2.rs @@ -136,7 +136,7 @@ pub fn hash_ecaps2(data: &[u8], algo: Algo) -> Result { Algo::Sha_1 => return Err(String::from("Disabled algorithm sha-1: unsafe.")), Algo::Unknown(algo) => return Err(format!("Unknown algorithm: {}.", algo)), }, - algo: algo, + algo, }) } diff --git a/src/iq.rs b/src/iq.rs index ccb503a..dd04e6b 100644 --- a/src/iq.rs +++ b/src/iq.rs @@ -96,7 +96,7 @@ impl Iq { from: None, to: None, id, - payload: IqType::Result(payload.map(|payload| payload.into())), + payload: IqType::Result(payload.map(Into::into)), } } @@ -188,9 +188,9 @@ impl TryFrom for Iq { }; Ok(Iq { - from: from, - to: to, - id: id, + from, + to, + id, payload: type_, }) } diff --git a/src/jingle.rs b/src/jingle.rs index 63c78a0..2596687 100644 --- a/src/jingle.rs +++ b/src/jingle.rs @@ -398,8 +398,8 @@ impl TryFrom for ReasonElement { "Reason doesn’t contain a valid reason.", ))?; Ok(ReasonElement { - reason: reason, - text: text, + reason, + text, }) } } @@ -449,8 +449,8 @@ impl Jingle { /// Create a new Jingle element. pub fn new(action: Action, sid: SessionId) -> Jingle { Jingle { - action: action, - sid: sid, + action, + sid, initiator: None, responder: None, contents: Vec::new(), diff --git a/src/jingle_ft.rs b/src/jingle_ft.rs index fce18cd..2d61569 100644 --- a/src/jingle_ft.rs +++ b/src/jingle_ft.rs @@ -47,7 +47,7 @@ generate_id!( ); /// Represents a file to be transferred. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct File { /// The date of last modification of this file. pub date: Option, @@ -74,15 +74,7 @@ pub struct File { impl File { /// Creates a new file descriptor. pub fn new() -> File { - File { - date: None, - media_type: None, - name: None, - descs: BTreeMap::new(), - size: None, - range: None, - hashes: Vec::new(), - } + File::default() } /// Sets the date of last modification on this file. diff --git a/src/jingle_s5b.rs b/src/jingle_s5b.rs index 58c4a27..613842f 100644 --- a/src/jingle_s5b.rs +++ b/src/jingle_s5b.rs @@ -232,10 +232,10 @@ impl TryFrom for Transport { } let payload = payload.unwrap_or(TransportPayload::None); Ok(Transport { - sid: sid, - dstaddr: dstaddr, - mode: mode, - payload: payload, + sid, + dstaddr, + mode, + payload, }) } } diff --git a/src/message.rs b/src/message.rs index fe32300..f2611ac 100644 --- a/src/message.rs +++ b/src/message.rs @@ -98,7 +98,7 @@ impl Message { pub fn new(to: Option) -> Message { Message { from: None, - to: to, + to, id: None, type_: MessageType::Chat, bodies: BTreeMap::new(), @@ -192,14 +192,14 @@ impl TryFrom for Message { } } Ok(Message { - from: from, - to: to, - id: id, - type_: type_, - bodies: bodies, - subjects: subjects, - thread: thread, - payloads: payloads, + from, + to, + id, + type_, + bodies, + subjects, + thread, + payloads, }) } } diff --git a/src/muc/muc.rs b/src/muc/muc.rs index 9d29cc9..a4e60a4 100644 --- a/src/muc/muc.rs +++ b/src/muc/muc.rs @@ -10,7 +10,7 @@ use crate::presence::PresencePayload; generate_element!( /// Represents the query for messages before our join. - #[derive(PartialEq)] + #[derive(PartialEq, Default)] History, "history", MUC, attributes: [ /// How many characters of history to send, in XML characters. @@ -30,12 +30,7 @@ generate_element!( impl History { /// Create a new empty history element. pub fn new() -> Self { - History { - maxchars: None, - maxstanzas: None, - seconds: None, - since: None, - } + History::default() } /// Set how many characters of history to send. @@ -65,7 +60,7 @@ impl History { generate_element!( /// Represents a room join request. - #[derive(PartialEq)] + #[derive(PartialEq, Default)] Muc, "x", MUC, children: [ /// Password to use when the room is protected by a password. password: Option = ("password", MUC) => String, @@ -80,10 +75,7 @@ impl PresencePayload for Muc {} impl Muc { /// Create a new MUC join element. pub fn new() -> Self { - Muc { - password: None, - history: None, - } + Muc::default() } /// Join a room with this password. diff --git a/src/muc/user.rs b/src/muc/user.rs index 46a8933..8232baf 100644 --- a/src/muc/user.rs +++ b/src/muc/user.rs @@ -100,9 +100,9 @@ impl TryFrom for Actor { match (jid, nick) { (Some(_), Some(_)) | (None, None) => { - return Err(Error::ParseError( + Err(Error::ParseError( "Either 'jid' or 'nick' attribute is required.", - )); + )) } (Some(jid), _) => Ok(Actor::Jid(jid)), (_, Some(nick)) => Ok(Actor::Nick(nick)), diff --git a/src/presence.rs b/src/presence.rs index 4a464f9..e7d2a55 100644 --- a/src/presence.rs +++ b/src/presence.rs @@ -197,7 +197,7 @@ impl Presence { from: None, to: None, id: None, - type_: type_, + type_, show: Show::None, statuses: BTreeMap::new(), priority: 0i8, diff --git a/src/pubsub/event.rs b/src/pubsub/event.rs index e0f2b59..0c616ab 100644 --- a/src/pubsub/event.rs +++ b/src/pubsub/event.rs @@ -178,7 +178,7 @@ impl TryFrom for PubSubEvent { } else if child.is("subscription", ns::PUBSUB_EVENT) { check_no_children!(child, "subscription"); payload = Some(PubSubEvent::Subscription { - node: node, + node, expiry: get_attr!(child, "expiry", optional), jid: get_attr!(child, "jid", optional), subid: get_attr!(child, "subid", optional), diff --git a/src/pubsub/mod.rs b/src/pubsub/mod.rs index 81e4e35..cde7e77 100644 --- a/src/pubsub/mod.rs +++ b/src/pubsub/mod.rs @@ -67,7 +67,7 @@ impl Item { Item { id, publisher, - payload: payload.map(|payload| payload.into()), + payload: payload.map(Into::into), } } } diff --git a/src/sasl.rs b/src/sasl.rs index fecdbfa..8f63f09 100644 --- a/src/sasl.rs +++ b/src/sasl.rs @@ -192,8 +192,8 @@ impl TryFrom for Failure { defined_condition.ok_or(Error::ParseError("Failure must have a defined-condition."))?; Ok(Failure { - defined_condition: defined_condition, - texts: texts, + defined_condition, + texts, }) } } diff --git a/src/sm.rs b/src/sm.rs index fc8e737..1f48615 100644 --- a/src/sm.rs +++ b/src/sm.rs @@ -31,6 +31,7 @@ generate_attribute!( generate_element!( /// Client request for enabling stream management. + #[derive(Default)] Enable, "enable", SM, attributes: [ /// The preferred resumption time in seconds by the client. @@ -45,10 +46,7 @@ generate_element!( impl Enable { /// Generates a new `` element. pub fn new() -> Self { - Enable { - max: None, - resume: ResumeAttr::False, - } + Enable::default() } /// Sets the preferred resumption time in seconds. diff --git a/src/stanza_error.rs b/src/stanza_error.rs index 7a4d421..d254f6b 100644 --- a/src/stanza_error.rs +++ b/src/stanza_error.rs @@ -258,11 +258,11 @@ impl TryFrom for StanzaError { defined_condition.ok_or(Error::ParseError("Error must have a defined-condition."))?; Ok(StanzaError { - type_: type_, - by: by, - defined_condition: defined_condition, - texts: texts, - other: other, + type_, + by, + defined_condition, + texts, + other, }) } } diff --git a/src/util/helpers.rs b/src/util/helpers.rs index 2aa3701..b383234 100644 --- a/src/util/helpers.rs +++ b/src/util/helpers.rs @@ -19,7 +19,7 @@ impl PlainText { } pub fn encode(string: &Option) -> Option { - string.as_ref().map(|text| text.to_owned()) + string.as_ref().map(ToOwned::to_owned) } } @@ -34,7 +34,7 @@ impl TrimmedPlainText { }) } - pub fn encode(string: &String) -> String { + pub fn encode(string: &str) -> String { string.to_owned() } } @@ -47,7 +47,7 @@ impl Base64 { Ok(base64::decode(s)?) } - pub fn encode(b: &Vec) -> Option { + pub fn encode(b: &[u8]) -> Option { Some(base64::encode(b)) } } @@ -57,11 +57,11 @@ pub struct WhitespaceAwareBase64; impl WhitespaceAwareBase64 { pub fn decode(s: &str) -> Result, Error> { - let s: String = s.chars().into_iter().filter(|ch| *ch != ' ' && *ch != '\n' && *ch != '\t').collect(); + let s: String = s.chars().filter(|ch| *ch != ' ' && *ch != '\n' && *ch != '\t').collect(); Ok(base64::decode(&s)?) } - pub fn encode(b: &Vec) -> Option { + pub fn encode(b: &[u8]) -> Option { Some(base64::encode(b)) } }