diff --git a/src/disco.rs b/src/disco.rs index a9d8b370..4ac7240e 100644 --- a/src/disco.rs +++ b/src/disco.rs @@ -98,12 +98,12 @@ pub fn parse_disco(root: &Element) -> Result { } */ - return Ok(Disco { + Ok(Disco { node: node, identities: identities, features: features, extensions: extensions - }); + }) } pub fn serialise_disco(disco: &Disco) -> Element { diff --git a/src/ecaps2.rs b/src/ecaps2.rs index da36f9e1..e2e2de18 100644 --- a/src/ecaps2.rs +++ b/src/ecaps2.rs @@ -15,13 +15,13 @@ use self::sha2::{Sha256, Sha512, Digest}; use self::sha3::{Sha3_256, Sha3_512}; use self::blake2::Blake2b; -fn compute_item(field: &String) -> Vec { +fn compute_item(field: &str) -> Vec { let mut bytes = field.as_bytes().to_vec(); bytes.push(0x1f); bytes } -fn compute_items Vec>(things: &Vec, separator: u8, encode: F) -> Vec { +fn compute_items Vec>(things: &[T], separator: u8, encode: F) -> Vec { let mut string: Vec = vec!(); let mut accumulator: Vec> = vec!(); for thing in things { @@ -37,22 +37,22 @@ fn compute_items Vec>(things: &Vec, separator: u8, encode string } -fn compute_features(features: &Vec) -> Vec { +fn compute_features(features: &[Feature]) -> Vec { compute_items(features, 0x1c, |feature| compute_item(&feature.var)) } -fn compute_identities(identities: &Vec) -> Vec { +fn compute_identities(identities: &[Identity]) -> Vec { compute_items(identities, 0x1c, |identity| { let mut bytes = compute_item(&identity.category); bytes.append(&mut compute_item(&identity.type_)); bytes.append(&mut compute_item(&identity.xml_lang)); - bytes.append(&mut compute_item(&identity.name.clone().unwrap_or(String::new()))); + bytes.append(&mut compute_item(&identity.name.clone().unwrap_or_default())); bytes.push(0x1e); bytes }) } -fn compute_extensions(extensions: &Vec) -> Vec { +fn compute_extensions(extensions: &[DataForm]) -> Vec { compute_items(extensions, 0x1c, |extension| { compute_items(&extension.fields, 0x1d, |field| { let mut bytes = compute_item(&field.var); @@ -81,7 +81,7 @@ pub fn convert_element(root: &Element) -> Result, Error> { Ok(final_string) } -pub fn hash_ecaps2(data: &Vec, algo: String) -> String { +pub fn hash_ecaps2(data: &[u8], algo: &str) -> String { match algo.as_ref() { "sha-256" => { let mut hasher = Sha256::default(); @@ -201,9 +201,9 @@ mod tests { assert_eq!(ecaps2.len(), 0x1d9); assert_eq!(ecaps2, expected); - let sha_256 = ecaps2::hash_ecaps2(&ecaps2, String::from("sha-256")); + let sha_256 = ecaps2::hash_ecaps2(&ecaps2, "sha-256"); assert_eq!(sha_256, "kzBZbkqJ3ADrj7v08reD1qcWUwNGHaidNUgD7nHpiw8="); - let sha3_256 = ecaps2::hash_ecaps2(&ecaps2, String::from("sha3-256")); + let sha3_256 = ecaps2::hash_ecaps2(&ecaps2, "sha3-256"); assert_eq!(sha3_256, "79mdYAfU9rEdTOcWDO7UEAt6E56SUzk/g6TnqUeuD9Q="); } @@ -372,9 +372,9 @@ mod tests { assert_eq!(ecaps2.len(), 0x543); assert_eq!(ecaps2, expected); - let sha_256 = ecaps2::hash_ecaps2(&ecaps2, String::from("sha-256")); + let sha_256 = ecaps2::hash_ecaps2(&ecaps2, "sha-256"); assert_eq!(sha_256, "u79ZroNJbdSWhdSp311mddz44oHHPsEBntQ5b1jqBSY="); - let sha3_256 = ecaps2::hash_ecaps2(&ecaps2, String::from("sha3-256")); + let sha3_256 = ecaps2::hash_ecaps2(&ecaps2, "sha3-256"); assert_eq!(sha3_256, "XpUJzLAc93258sMECZ3FJpebkzuyNXDzRNwQog8eycg="); } } diff --git a/src/ibb.rs b/src/ibb.rs index 00d30f3f..2e99506b 100644 --- a/src/ibb.rs +++ b/src/ibb.rs @@ -54,7 +54,7 @@ pub fn parse_ibb(root: &Element) -> Result { let sid = required_attr(root, "sid", Error::ParseError("Required attribute 'sid' missing in open element."))?; let stanza = root.attr("stanza") .and_then(|value| value.parse().ok()) - .unwrap_or(Default::default()); + .unwrap_or_default(); for _ in root.children() { return Err(Error::ParseError("Unknown child in open element.")); } diff --git a/src/jingle.rs b/src/jingle.rs index 2b7f253f..0caba248 100644 --- a/src/jingle.rs +++ b/src/jingle.rs @@ -308,14 +308,14 @@ pub fn parse_jingle(root: &Element) -> Result { } } - return Ok(Jingle { + Ok(Jingle { action: action, initiator: initiator, responder: responder, sid: sid.to_owned(), contents: contents, reason: reason_element, - }); + }) } #[cfg(test)]