Fix clippy lints.

This commit is contained in:
Emmanuel Gil Peyrot 2019-02-21 21:00:58 +01:00
parent 63dcba03b2
commit 637c3eadd7
20 changed files with 56 additions and 75 deletions

View file

@ -49,6 +49,7 @@ generate_element!(
generate_element!( generate_element!(
/// Container element for multiple bookmarks. /// Container element for multiple bookmarks.
#[derive(Default)]
Storage, "storage", BOOKMARKS, Storage, "storage", BOOKMARKS,
children: [ children: [
/// Conferences the user has expressed an interest in. /// Conferences the user has expressed an interest in.
@ -62,10 +63,7 @@ generate_element!(
impl Storage { impl Storage {
/// Create an empty bookmarks storage. /// Create an empty bookmarks storage.
pub fn new() -> Storage { pub fn new() -> Storage {
Storage { Storage::default()
conferences: Vec::new(),
urls: Vec::new(),
}
} }
} }

View file

@ -54,7 +54,7 @@ impl TryFrom<Element> for Caps {
Ok(Caps { Ok(Caps {
ext: get_attr!(elem, "ext", optional), ext: get_attr!(elem, "ext", optional),
node: get_attr!(elem, "node", required), node: get_attr!(elem, "node", required),
hash: hash, hash,
}) })
} }
} }
@ -202,7 +202,7 @@ pub fn hash_caps(data: &[u8], algo: Algo) -> Result<Hash, String> {
} }
Algo::Unknown(algo) => return Err(format!("Unknown algorithm: {}.", algo)), Algo::Unknown(algo) => return Err(format!("Unknown algorithm: {}.", algo)),
}, },
algo: algo, algo,
}) })
} }

View file

@ -10,6 +10,7 @@ use sha1::Sha1;
generate_element!( generate_element!(
/// The main authentication mechanism for components. /// The main authentication mechanism for components.
#[derive(Default)]
Handshake, "handshake", COMPONENT, Handshake, "handshake", COMPONENT,
text: ( text: (
/// If Some, contains the hex-encoded SHA-1 of the concatenation of the /// If Some, contains the hex-encoded SHA-1 of the concatenation of the
@ -25,7 +26,7 @@ generate_element!(
impl Handshake { impl Handshake {
/// Creates a successful reply from a server. /// Creates a successful reply from a server.
pub fn new() -> Handshake { pub fn new() -> Handshake {
Handshake { data: None } Handshake::default()
} }
/// Creates an authentication request from the component. /// Creates an authentication request from the component.

View file

@ -222,7 +222,7 @@ impl TryFrom<Element> for DataForm {
check_no_unknown_attributes!(elem, "x", ["type"]); check_no_unknown_attributes!(elem, "x", ["type"]);
let type_ = get_attr!(elem, "type", required); let type_ = get_attr!(elem, "type", required);
let mut form = DataForm { let mut form = DataForm {
type_: type_, type_,
form_type: None, form_type: None,
title: None, title: None,
instructions: None, instructions: None,

View file

@ -86,8 +86,8 @@ impl TryFrom<Element> for Identity {
} }
Ok(Identity { Ok(Identity {
category: category, category,
type_: type_, type_,
lang: get_attr!(elem, "xml:lang", optional), lang: get_attr!(elem, "xml:lang", optional),
name: get_attr!(elem, "name", optional), name: get_attr!(elem, "name", optional),
}) })

View file

@ -136,7 +136,7 @@ pub fn hash_ecaps2(data: &[u8], algo: Algo) -> Result<Hash, String> {
Algo::Sha_1 => return Err(String::from("Disabled algorithm sha-1: unsafe.")), Algo::Sha_1 => return Err(String::from("Disabled algorithm sha-1: unsafe.")),
Algo::Unknown(algo) => return Err(format!("Unknown algorithm: {}.", algo)), Algo::Unknown(algo) => return Err(format!("Unknown algorithm: {}.", algo)),
}, },
algo: algo, algo,
}) })
} }

View file

@ -96,7 +96,7 @@ impl Iq {
from: None, from: None,
to: None, to: None,
id, id,
payload: IqType::Result(payload.map(|payload| payload.into())), payload: IqType::Result(payload.map(Into::into)),
} }
} }
@ -188,9 +188,9 @@ impl TryFrom<Element> for Iq {
}; };
Ok(Iq { Ok(Iq {
from: from, from,
to: to, to,
id: id, id,
payload: type_, payload: type_,
}) })
} }

View file

@ -398,8 +398,8 @@ impl TryFrom<Element> for ReasonElement {
"Reason doesnt contain a valid reason.", "Reason doesnt contain a valid reason.",
))?; ))?;
Ok(ReasonElement { Ok(ReasonElement {
reason: reason, reason,
text: text, text,
}) })
} }
} }
@ -449,8 +449,8 @@ impl Jingle {
/// Create a new Jingle element. /// Create a new Jingle element.
pub fn new(action: Action, sid: SessionId) -> Jingle { pub fn new(action: Action, sid: SessionId) -> Jingle {
Jingle { Jingle {
action: action, action,
sid: sid, sid,
initiator: None, initiator: None,
responder: None, responder: None,
contents: Vec::new(), contents: Vec::new(),

View file

@ -47,7 +47,7 @@ generate_id!(
); );
/// Represents a file to be transferred. /// Represents a file to be transferred.
#[derive(Debug, Clone)] #[derive(Debug, Clone, Default)]
pub struct File { pub struct File {
/// The date of last modification of this file. /// The date of last modification of this file.
pub date: Option<DateTime>, pub date: Option<DateTime>,
@ -74,15 +74,7 @@ pub struct File {
impl File { impl File {
/// Creates a new file descriptor. /// Creates a new file descriptor.
pub fn new() -> File { pub fn new() -> File {
File { File::default()
date: None,
media_type: None,
name: None,
descs: BTreeMap::new(),
size: None,
range: None,
hashes: Vec::new(),
}
} }
/// Sets the date of last modification on this file. /// Sets the date of last modification on this file.

View file

@ -232,10 +232,10 @@ impl TryFrom<Element> for Transport {
} }
let payload = payload.unwrap_or(TransportPayload::None); let payload = payload.unwrap_or(TransportPayload::None);
Ok(Transport { Ok(Transport {
sid: sid, sid,
dstaddr: dstaddr, dstaddr,
mode: mode, mode,
payload: payload, payload,
}) })
} }
} }

View file

@ -98,7 +98,7 @@ impl Message {
pub fn new(to: Option<Jid>) -> Message { pub fn new(to: Option<Jid>) -> Message {
Message { Message {
from: None, from: None,
to: to, to,
id: None, id: None,
type_: MessageType::Chat, type_: MessageType::Chat,
bodies: BTreeMap::new(), bodies: BTreeMap::new(),
@ -192,14 +192,14 @@ impl TryFrom<Element> for Message {
} }
} }
Ok(Message { Ok(Message {
from: from, from,
to: to, to,
id: id, id,
type_: type_, type_,
bodies: bodies, bodies,
subjects: subjects, subjects,
thread: thread, thread,
payloads: payloads, payloads,
}) })
} }
} }

View file

@ -10,7 +10,7 @@ use crate::presence::PresencePayload;
generate_element!( generate_element!(
/// Represents the query for messages before our join. /// Represents the query for messages before our join.
#[derive(PartialEq)] #[derive(PartialEq, Default)]
History, "history", MUC, History, "history", MUC,
attributes: [ attributes: [
/// How many characters of history to send, in XML characters. /// How many characters of history to send, in XML characters.
@ -30,12 +30,7 @@ generate_element!(
impl History { impl History {
/// Create a new empty history element. /// Create a new empty history element.
pub fn new() -> Self { pub fn new() -> Self {
History { History::default()
maxchars: None,
maxstanzas: None,
seconds: None,
since: None,
}
} }
/// Set how many characters of history to send. /// Set how many characters of history to send.
@ -65,7 +60,7 @@ impl History {
generate_element!( generate_element!(
/// Represents a room join request. /// Represents a room join request.
#[derive(PartialEq)] #[derive(PartialEq, Default)]
Muc, "x", MUC, children: [ Muc, "x", MUC, children: [
/// Password to use when the room is protected by a password. /// Password to use when the room is protected by a password.
password: Option<String> = ("password", MUC) => String, password: Option<String> = ("password", MUC) => String,
@ -80,10 +75,7 @@ impl PresencePayload for Muc {}
impl Muc { impl Muc {
/// Create a new MUC join element. /// Create a new MUC join element.
pub fn new() -> Self { pub fn new() -> Self {
Muc { Muc::default()
password: None,
history: None,
}
} }
/// Join a room with this password. /// Join a room with this password.

View file

@ -100,9 +100,9 @@ impl TryFrom<Element> for Actor {
match (jid, nick) { match (jid, nick) {
(Some(_), Some(_)) | (None, None) => { (Some(_), Some(_)) | (None, None) => {
return Err(Error::ParseError( Err(Error::ParseError(
"Either 'jid' or 'nick' attribute is required.", "Either 'jid' or 'nick' attribute is required.",
)); ))
} }
(Some(jid), _) => Ok(Actor::Jid(jid)), (Some(jid), _) => Ok(Actor::Jid(jid)),
(_, Some(nick)) => Ok(Actor::Nick(nick)), (_, Some(nick)) => Ok(Actor::Nick(nick)),

View file

@ -197,7 +197,7 @@ impl Presence {
from: None, from: None,
to: None, to: None,
id: None, id: None,
type_: type_, type_,
show: Show::None, show: Show::None,
statuses: BTreeMap::new(), statuses: BTreeMap::new(),
priority: 0i8, priority: 0i8,

View file

@ -178,7 +178,7 @@ impl TryFrom<Element> for PubSubEvent {
} else if child.is("subscription", ns::PUBSUB_EVENT) { } else if child.is("subscription", ns::PUBSUB_EVENT) {
check_no_children!(child, "subscription"); check_no_children!(child, "subscription");
payload = Some(PubSubEvent::Subscription { payload = Some(PubSubEvent::Subscription {
node: node, node,
expiry: get_attr!(child, "expiry", optional), expiry: get_attr!(child, "expiry", optional),
jid: get_attr!(child, "jid", optional), jid: get_attr!(child, "jid", optional),
subid: get_attr!(child, "subid", optional), subid: get_attr!(child, "subid", optional),

View file

@ -67,7 +67,7 @@ impl Item {
Item { Item {
id, id,
publisher, publisher,
payload: payload.map(|payload| payload.into()), payload: payload.map(Into::into),
} }
} }
} }

View file

@ -192,8 +192,8 @@ impl TryFrom<Element> for Failure {
defined_condition.ok_or(Error::ParseError("Failure must have a defined-condition."))?; defined_condition.ok_or(Error::ParseError("Failure must have a defined-condition."))?;
Ok(Failure { Ok(Failure {
defined_condition: defined_condition, defined_condition,
texts: texts, texts,
}) })
} }
} }

View file

@ -31,6 +31,7 @@ generate_attribute!(
generate_element!( generate_element!(
/// Client request for enabling stream management. /// Client request for enabling stream management.
#[derive(Default)]
Enable, "enable", SM, Enable, "enable", SM,
attributes: [ attributes: [
/// The preferred resumption time in seconds by the client. /// The preferred resumption time in seconds by the client.
@ -45,10 +46,7 @@ generate_element!(
impl Enable { impl Enable {
/// Generates a new `<enable/>` element. /// Generates a new `<enable/>` element.
pub fn new() -> Self { pub fn new() -> Self {
Enable { Enable::default()
max: None,
resume: ResumeAttr::False,
}
} }
/// Sets the preferred resumption time in seconds. /// Sets the preferred resumption time in seconds.

View file

@ -258,11 +258,11 @@ impl TryFrom<Element> for StanzaError {
defined_condition.ok_or(Error::ParseError("Error must have a defined-condition."))?; defined_condition.ok_or(Error::ParseError("Error must have a defined-condition."))?;
Ok(StanzaError { Ok(StanzaError {
type_: type_, type_,
by: by, by,
defined_condition: defined_condition, defined_condition,
texts: texts, texts,
other: other, other,
}) })
} }
} }

View file

@ -19,7 +19,7 @@ impl PlainText {
} }
pub fn encode(string: &Option<String>) -> Option<String> { pub fn encode(string: &Option<String>) -> Option<String> {
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() string.to_owned()
} }
} }
@ -47,7 +47,7 @@ impl Base64 {
Ok(base64::decode(s)?) Ok(base64::decode(s)?)
} }
pub fn encode(b: &Vec<u8>) -> Option<String> { pub fn encode(b: &[u8]) -> Option<String> {
Some(base64::encode(b)) Some(base64::encode(b))
} }
} }
@ -57,11 +57,11 @@ pub struct WhitespaceAwareBase64;
impl WhitespaceAwareBase64 { impl WhitespaceAwareBase64 {
pub fn decode(s: &str) -> Result<Vec<u8>, Error> { pub fn decode(s: &str) -> Result<Vec<u8>, 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)?) Ok(base64::decode(&s)?)
} }
pub fn encode(b: &Vec<u8>) -> Option<String> { pub fn encode(b: &[u8]) -> Option<String> {
Some(base64::encode(b)) Some(base64::encode(b))
} }
} }