Impl Display for Jid

This commit is contained in:
Randy von der Weide 2019-08-31 13:17:51 +00:00 committed by Maxime Buquet
parent bf1c2bd48b
commit 56986a68e4

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() {