Run cargo fmt.

This commit is contained in:
Emmanuel Gil Peyrot 2018-12-18 16:40:44 +01:00
commit fa0894daa0

View file

@ -4,12 +4,11 @@
//! //!
//! For usage, check the documentation on the `Jid` struct. //! For usage, check the documentation on the `Jid` struct.
#[macro_use] extern crate failure_derive; #[macro_use]
extern crate failure_derive;
use std::fmt;
use std::convert::Into; use std::convert::Into;
use std::fmt;
use std::str::FromStr; use std::str::FromStr;
/// An error that signifies that a `Jid` cannot be parsed from a string. /// An error that signifies that a `Jid` cannot be parsed from a string.
@ -77,7 +76,7 @@ impl fmt::Display for Jid {
enum ParserState { enum ParserState {
Node, Node,
Domain, Domain,
Resource Resource,
} }
impl FromStr for Jid { impl FromStr for Jid {
@ -102,7 +101,7 @@ impl FromStr for Jid {
state = ParserState::Domain; state = ParserState::Domain;
node = Some(buf.clone()); // TODO: performance tweaks, do not need to copy it node = Some(buf.clone()); // TODO: performance tweaks, do not need to copy it
buf.clear(); buf.clear();
}, }
'/' => { '/' => {
if buf == "" { if buf == "" {
return Err(JidParseError::NoDomain); return Err(JidParseError::NoDomain);
@ -110,12 +109,12 @@ impl FromStr for Jid {
state = ParserState::Resource; state = ParserState::Resource;
domain = Some(buf.clone()); // TODO: performance tweaks domain = Some(buf.clone()); // TODO: performance tweaks
buf.clear(); buf.clear();
}, }
c => { c => {
buf.push(c); buf.push(c);
}, }
} }
}, }
ParserState::Domain => { ParserState::Domain => {
match c { match c {
'/' => { '/' => {
@ -125,28 +124,28 @@ impl FromStr for Jid {
state = ParserState::Resource; state = ParserState::Resource;
domain = Some(buf.clone()); // TODO: performance tweaks domain = Some(buf.clone()); // TODO: performance tweaks
buf.clear(); buf.clear();
}, }
c => { c => {
buf.push(c); buf.push(c);
}, }
} }
}, }
ParserState::Resource => { ParserState::Resource => {
buf.push(c); buf.push(c);
}, }
} }
} }
if !buf.is_empty() { if !buf.is_empty() {
match state { match state {
ParserState::Node => { ParserState::Node => {
domain = Some(buf); domain = Some(buf);
}, }
ParserState::Domain => { ParserState::Domain => {
domain = Some(buf); domain = Some(buf);
}, }
ParserState::Resource => { ParserState::Resource => {
resource = Some(buf); resource = Some(buf);
}, }
} }
} else if let ParserState::Resource = state { } else if let ParserState::Resource = state {
return Err(JidParseError::EmptyResource); return Err(JidParseError::EmptyResource);
@ -176,9 +175,11 @@ impl Jid {
/// assert_eq!(jid.resource, Some("resource".to_owned())); /// assert_eq!(jid.resource, Some("resource".to_owned()));
/// ``` /// ```
pub fn full<NS, DS, RS>(node: NS, domain: DS, resource: RS) -> Jid pub fn full<NS, DS, RS>(node: NS, domain: DS, resource: RS) -> Jid
where NS: Into<String> where
, DS: Into<String> NS: Into<String>,
, RS: Into<String> { DS: Into<String>,
RS: Into<String>,
{
Jid { Jid {
node: Some(node.into()), node: Some(node.into()),
domain: domain.into(), domain: domain.into(),
@ -202,8 +203,10 @@ impl Jid {
/// assert_eq!(jid.resource, None); /// assert_eq!(jid.resource, None);
/// ``` /// ```
pub fn bare<NS, DS>(node: NS, domain: DS) -> Jid pub fn bare<NS, DS>(node: NS, domain: DS) -> Jid
where NS: Into<String> where
, DS: Into<String> { NS: Into<String>,
DS: Into<String>,
{
Jid { Jid {
node: Some(node.into()), node: Some(node.into()),
domain: domain.into(), domain: domain.into(),
@ -250,7 +253,9 @@ impl Jid {
/// assert_eq!(jid.resource, None); /// assert_eq!(jid.resource, None);
/// ``` /// ```
pub fn domain<DS>(domain: DS) -> Jid pub fn domain<DS>(domain: DS) -> Jid
where DS: Into<String> { where
DS: Into<String>,
{
Jid { Jid {
node: None, node: None,
domain: domain.into(), domain: domain.into(),
@ -297,8 +302,10 @@ impl Jid {
/// assert_eq!(jid.resource, Some("resource".to_owned())); /// assert_eq!(jid.resource, Some("resource".to_owned()));
/// ``` /// ```
pub fn domain_with_resource<DS, RS>(domain: DS, resource: RS) -> Jid pub fn domain_with_resource<DS, RS>(domain: DS, resource: RS) -> Jid
where DS: Into<String> where
, RS: Into<String> { DS: Into<String>,
RS: Into<String>,
{
Jid { Jid {
node: None, node: None,
domain: domain.into(), domain: domain.into(),
@ -322,7 +329,9 @@ impl Jid {
/// assert_eq!(new_jid.node, Some("node".to_owned())); /// assert_eq!(new_jid.node, Some("node".to_owned()));
/// ``` /// ```
pub fn with_node<S>(&self, node: S) -> Jid pub fn with_node<S>(&self, node: S) -> Jid
where S: Into<String> { where
S: Into<String>,
{
Jid { Jid {
node: Some(node.into()), node: Some(node.into()),
domain: self.domain.clone(), domain: self.domain.clone(),
@ -346,7 +355,9 @@ impl Jid {
/// assert_eq!(new_jid.domain, "new_domain"); /// assert_eq!(new_jid.domain, "new_domain");
/// ``` /// ```
pub fn with_domain<S>(&self, domain: S) -> Jid pub fn with_domain<S>(&self, domain: S) -> Jid
where S: Into<String> { where
S: Into<String>,
{
Jid { Jid {
node: self.node.clone(), node: self.node.clone(),
domain: domain.into(), domain: domain.into(),
@ -370,18 +381,19 @@ impl Jid {
/// assert_eq!(new_jid.resource, Some("resource".to_owned())); /// assert_eq!(new_jid.resource, Some("resource".to_owned()));
/// ``` /// ```
pub fn with_resource<S>(&self, resource: S) -> Jid pub fn with_resource<S>(&self, resource: S) -> Jid
where S: Into<String> { where
S: Into<String>,
{
Jid { Jid {
node: self.node.clone(), node: self.node.clone(),
domain: self.domain.clone(), domain: self.domain.clone(),
resource: Some(resource.into()), resource: Some(resource.into()),
} }
} }
} }
#[cfg(feature = "minidom")] #[cfg(feature = "minidom")]
use minidom::{IntoAttributeValue, IntoElements, ElementEmitter}; use minidom::{ElementEmitter, IntoAttributeValue, IntoElements};
#[cfg(feature = "minidom")] #[cfg(feature = "minidom")]
impl IntoAttributeValue for Jid { 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/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("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("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] #[test]
fn serialise() { 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] #[test]