From 27ddad683af52dbcf5df9d90846b5f66cf88ce54 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 27 Nov 2020 20:57:01 +0100 Subject: [PATCH] xmpp-parsers/jingle: Implement Display on ReasonElement. --- xmpp-parsers/src/jingle.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/xmpp-parsers/src/jingle.rs b/xmpp-parsers/src/jingle.rs index 5db03c06..1e357f30 100644 --- a/xmpp-parsers/src/jingle.rs +++ b/xmpp-parsers/src/jingle.rs @@ -15,6 +15,7 @@ use crate::Element; use jid::Jid; use std::collections::BTreeMap; use std::convert::TryFrom; +use std::fmt; use std::str::FromStr; generate_attribute!( @@ -472,6 +473,18 @@ pub struct ReasonElement { pub texts: BTreeMap, } +impl fmt::Display for ReasonElement { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + write!(fmt, "{}", Element::from(self.reason.clone()).name())?; + if let Some(text) = self.texts.get("en") { + write!(fmt, ": {}", text)?; + } else if let Some(text) = self.texts.get("") { + write!(fmt, ": {}", text)?; + } + Ok(()) + } +} + impl TryFrom for ReasonElement { type Error = Error;