From fa0894daa06f88db0531e542875bbce332bb83d0 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 18 Dec 2018 16:40:44 +0100 Subject: [PATCH] Run `cargo fmt`. --- src/lib.rs | 80 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2861ef6e..dd9a5f1b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,12 +4,11 @@ //! //! For usage, check the documentation on the `Jid` struct. -#[macro_use] extern crate failure_derive; - -use std::fmt; +#[macro_use] +extern crate failure_derive; use std::convert::Into; - +use std::fmt; use std::str::FromStr; /// An error that signifies that a `Jid` cannot be parsed from a string. @@ -77,7 +76,7 @@ impl fmt::Display for Jid { enum ParserState { Node, Domain, - Resource + Resource, } impl FromStr for Jid { @@ -102,7 +101,7 @@ impl FromStr for Jid { state = ParserState::Domain; node = Some(buf.clone()); // TODO: performance tweaks, do not need to copy it buf.clear(); - }, + } '/' => { if buf == "" { return Err(JidParseError::NoDomain); @@ -110,12 +109,12 @@ impl FromStr for Jid { state = ParserState::Resource; domain = Some(buf.clone()); // TODO: performance tweaks buf.clear(); - }, + } c => { buf.push(c); - }, + } } - }, + } ParserState::Domain => { match c { '/' => { @@ -125,28 +124,28 @@ impl FromStr for Jid { state = ParserState::Resource; domain = Some(buf.clone()); // TODO: performance tweaks buf.clear(); - }, + } c => { buf.push(c); - }, + } } - }, + } ParserState::Resource => { buf.push(c); - }, + } } } if !buf.is_empty() { match state { ParserState::Node => { domain = Some(buf); - }, + } ParserState::Domain => { domain = Some(buf); - }, + } ParserState::Resource => { resource = Some(buf); - }, + } } } else if let ParserState::Resource = state { return Err(JidParseError::EmptyResource); @@ -176,9 +175,11 @@ impl Jid { /// assert_eq!(jid.resource, Some("resource".to_owned())); /// ``` pub fn full(node: NS, domain: DS, resource: RS) -> Jid - where NS: Into - , DS: Into - , RS: Into { + where + NS: Into, + DS: Into, + RS: Into, + { Jid { node: Some(node.into()), domain: domain.into(), @@ -202,8 +203,10 @@ impl Jid { /// assert_eq!(jid.resource, None); /// ``` pub fn bare(node: NS, domain: DS) -> Jid - where NS: Into - , DS: Into { + where + NS: Into, + DS: Into, + { Jid { node: Some(node.into()), domain: domain.into(), @@ -250,7 +253,9 @@ impl Jid { /// assert_eq!(jid.resource, None); /// ``` pub fn domain(domain: DS) -> Jid - where DS: Into { + where + DS: Into, + { Jid { node: None, domain: domain.into(), @@ -297,8 +302,10 @@ impl Jid { /// assert_eq!(jid.resource, Some("resource".to_owned())); /// ``` pub fn domain_with_resource(domain: DS, resource: RS) -> Jid - where DS: Into - , RS: Into { + where + DS: Into, + RS: Into, + { Jid { node: None, domain: domain.into(), @@ -322,7 +329,9 @@ impl Jid { /// assert_eq!(new_jid.node, Some("node".to_owned())); /// ``` pub fn with_node(&self, node: S) -> Jid - where S: Into { + where + S: Into, + { Jid { node: Some(node.into()), domain: self.domain.clone(), @@ -346,7 +355,9 @@ impl Jid { /// assert_eq!(new_jid.domain, "new_domain"); /// ``` pub fn with_domain(&self, domain: S) -> Jid - where S: Into { + where + S: Into, + { Jid { node: self.node.clone(), domain: domain.into(), @@ -370,18 +381,19 @@ impl Jid { /// assert_eq!(new_jid.resource, Some("resource".to_owned())); /// ``` pub fn with_resource(&self, resource: S) -> Jid - where S: Into { + where + S: Into, + { Jid { node: self.node.clone(), domain: self.domain.clone(), resource: Some(resource.into()), } } - } #[cfg(feature = "minidom")] -use minidom::{IntoAttributeValue, IntoElements, ElementEmitter}; +use minidom::{ElementEmitter, IntoAttributeValue, IntoElements}; #[cfg(feature = "minidom")] impl IntoAttributeValue for Jid { @@ -408,12 +420,18 @@ mod tests { assert_eq!(Jid::from_str("a@b.c/d"), Ok(Jid::full("a", "b.c", "d"))); assert_eq!(Jid::from_str("a@b.c"), Ok(Jid::bare("a", "b.c"))); assert_eq!(Jid::from_str("b.c"), Ok(Jid::domain("b.c"))); - assert_eq!(Jid::from_str("a/b@c"), Ok(Jid::domain_with_resource("a", "b@c"))); + assert_eq!( + Jid::from_str("a/b@c"), + Ok(Jid::domain_with_resource("a", "b@c")) + ); } #[test] fn serialise() { - assert_eq!(String::from(Jid::full("a", "b", "c")), String::from("a@b/c")); + assert_eq!( + String::from(Jid::full("a", "b", "c")), + String::from("a@b/c") + ); } #[test]