xmpp-parsers/jingle: Implement Display on ReasonElement.

This commit is contained in:
Emmanuel Gil Peyrot 2020-11-27 20:57:01 +01:00
parent 026b7d3c12
commit 27ddad683a

View file

@ -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<Lang, String>,
}
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<Element> for ReasonElement {
type Error = Error;