diff --git a/src/delay.rs b/src/delay.rs index e95ed4c..6904ca8 100644 --- a/src/delay.rs +++ b/src/delay.rs @@ -13,43 +13,15 @@ use error::Error; use jid::Jid; use ns; +use helpers::PlainText; -#[derive(Debug, Clone)] -pub struct Delay { - pub from: Option, - pub stamp: DateTime, - pub data: Option, -} - -impl TryFrom for Delay { - type Err = Error; - - fn try_from(elem: Element) -> Result { - check_self!(elem, "delay", ns::DELAY); - check_no_children!(elem, "delay"); - check_no_unknown_attributes!(elem, "delay", ["from", "stamp"]); - let data = match elem.text().as_ref() { - "" => None, - text => Some(text.to_owned()), - }; - Ok(Delay { - from: get_attr!(elem, "from", optional), - stamp: get_attr!(elem, "stamp", required), - data: data, - }) - } -} - -impl From for Element { - fn from(delay: Delay) -> Element { - Element::builder("delay") - .ns(ns::DELAY) - .attr("from", delay.from) - .attr("stamp", delay.stamp) - .append(delay.data) - .build() - } -} +generate_element_with_text!(Delay, "delay", ns::DELAY, + [ + from: Option = "from" => optional, + stamp: DateTime = "stamp" => required + ], + data: PlainText> +); #[cfg(test)] mod tests {