mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
delay: Use the new helper macro.
This commit is contained in:
parent
32e373be03
commit
682bb34b0b
1 changed files with 8 additions and 36 deletions
44
src/delay.rs
44
src/delay.rs
|
@ -13,43 +13,15 @@ use error::Error;
|
||||||
use jid::Jid;
|
use jid::Jid;
|
||||||
|
|
||||||
use ns;
|
use ns;
|
||||||
|
use helpers::PlainText;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
generate_element_with_text!(Delay, "delay", ns::DELAY,
|
||||||
pub struct Delay {
|
[
|
||||||
pub from: Option<Jid>,
|
from: Option<Jid> = "from" => optional,
|
||||||
pub stamp: DateTime,
|
stamp: DateTime = "stamp" => required
|
||||||
pub data: Option<String>,
|
],
|
||||||
}
|
data: PlainText<Option<String>>
|
||||||
|
);
|
||||||
impl TryFrom<Element> for Delay {
|
|
||||||
type Err = Error;
|
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<Delay, Error> {
|
|
||||||
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<Delay> 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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
Loading…
Reference in a new issue