Merge branch 'master' into 'master'

Impl Display for Jid

See merge request xmpp-rs/jid-rs!18
This commit is contained in:
Maxime Buquet 2019-08-31 13:17:51 +00:00
commit d5789ea1d1

View file

@ -92,6 +92,12 @@ impl From<FullJid> for Jid {
}
}
impl fmt::Display for Jid {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fmt.write_str(String::from(self.clone()).as_ref())
}
}
impl Jid {
/// The node part of the Jabber ID, if it exists, else None.
pub fn node(self) -> Option<String> {
@ -696,6 +702,14 @@ mod tests {
assert_eq!(FullJid::from_str("a@b"), Err(JidParseError::NoResource));
}
#[test]
fn display_jids() {
assert_eq!(format!("{}", FullJid::new("a", "b", "c")), String::from("a@b/c"));
assert_eq!(format!("{}", BareJid::new("a", "b")), String::from("a@b"));
assert_eq!(format!("{}", Jid::Full(FullJid::new("a", "b", "c"))), String::from("a@b/c"));
assert_eq!(format!("{}", Jid::Bare(BareJid::new("a", "b"))), String::from("a@b"));
}
#[cfg(feature = "minidom")]
#[test]
fn minidom() {