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!(
/// 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()
}
}

View file

@ -54,7 +54,7 @@ impl TryFrom<Element> 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<Hash, String> {
}
Algo::Unknown(algo) => return Err(format!("Unknown algorithm: {}.", algo)),
},
algo: algo,
algo,
})
}

View file

@ -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.

View file

@ -222,7 +222,7 @@ impl TryFrom<Element> 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,

View file

@ -86,8 +86,8 @@ impl TryFrom<Element> for Identity {
}
Ok(Identity {
category: category,
type_: type_,
category,
type_,
lang: get_attr!(elem, "xml:lang", 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::Unknown(algo) => return Err(format!("Unknown algorithm: {}.", algo)),
},
algo: algo,
algo,
})
}

View file

@ -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<Element> for Iq {
};
Ok(Iq {
from: from,
to: to,
id: id,
from,
to,
id,
payload: type_,
})
}

View file

@ -398,8 +398,8 @@ impl TryFrom<Element> for ReasonElement {
"Reason doesnt 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(),

View file

@ -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<DateTime>,
@ -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.

View file

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

View file

@ -98,7 +98,7 @@ impl Message {
pub fn new(to: Option<Jid>) -> Message {
Message {
from: None,
to: to,
to,
id: None,
type_: MessageType::Chat,
bodies: BTreeMap::new(),
@ -192,14 +192,14 @@ impl TryFrom<Element> 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,
})
}
}

View file

@ -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<String> = ("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.

View file

@ -100,9 +100,9 @@ impl TryFrom<Element> 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)),

View file

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

View file

@ -178,7 +178,7 @@ impl TryFrom<Element> 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),

View file

@ -67,7 +67,7 @@ impl Item {
Item {
id,
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."))?;
Ok(Failure {
defined_condition: defined_condition,
texts: texts,
defined_condition,
texts,
})
}
}

View file

@ -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 `<enable/>` element.
pub fn new() -> Self {
Enable {
max: None,
resume: ResumeAttr::False,
}
Enable::default()
}
/// 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."))?;
Ok(StanzaError {
type_: type_,
by: by,
defined_condition: defined_condition,
texts: texts,
other: other,
type_,
by,
defined_condition,
texts,
other,
})
}
}

View file

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