From f049e3626b5707fd5bd710c22b9b81ea58d30ae8 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 4 Aug 2024 17:42:07 +0200 Subject: [PATCH] xmpp-parsers: Convert OOB to xso --- parsers/src/oob.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/parsers/src/oob.rs b/parsers/src/oob.rs index dbcb490c..c2a53ab4 100644 --- a/parsers/src/oob.rs +++ b/parsers/src/oob.rs @@ -4,19 +4,23 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. +use xso::{AsXml, FromXml}; + use crate::message::MessagePayload; +use crate::ns; -generate_element!( - /// Defines associated out of band url. - Oob, "x", OOB, - children: [ - /// The associated URL. - url: Required = ("url", OOB) => String, +/// Defines associated out of band url. +#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] +#[xml(namespace = ns::OOB, name = "x")] +pub struct Oob { + /// The associated URL. + #[xml(extract(fields(text)))] + pub url: String, - /// An optional description of the out of band data. - desc: Option = ("desc", OOB) => String, - ] -); + /// An optional description of the out of band data. + #[xml(extract(default, fields(text(type_ = String))))] + pub desc: Option, +} impl MessagePayload for Oob {} @@ -63,6 +67,6 @@ mod tests { FromElementError::Invalid(Error::Other(string)) => string, _ => panic!(), }; - assert_eq!(message, "Missing child url in x element."); + assert_eq!(message, "Missing child field 'url' in Oob element."); } }