delay: Use Jid for from attribute.
This commit is contained in:
parent
ed458ba694
commit
7b6d444f03
1 changed files with 7 additions and 4 deletions
11
src/delay.rs
11
src/delay.rs
|
|
@ -8,12 +8,13 @@ use minidom::{Element, IntoElements};
|
||||||
use minidom::convert::ElementEmitter;
|
use minidom::convert::ElementEmitter;
|
||||||
|
|
||||||
use error::Error;
|
use error::Error;
|
||||||
|
use jid::Jid;
|
||||||
|
|
||||||
use ns;
|
use ns;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Delay {
|
pub struct Delay {
|
||||||
pub from: Option<String>,
|
pub from: Option<Jid>,
|
||||||
pub stamp: String,
|
pub stamp: String,
|
||||||
pub data: Option<String>,
|
pub data: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +42,7 @@ pub fn parse_delay(root: &Element) -> Result<Delay, Error> {
|
||||||
pub fn serialise(delay: &Delay) -> Element {
|
pub fn serialise(delay: &Delay) -> Element {
|
||||||
Element::builder("delay")
|
Element::builder("delay")
|
||||||
.ns(ns::DELAY)
|
.ns(ns::DELAY)
|
||||||
.attr("from", delay.from.clone())
|
.attr("from", delay.from.clone().and_then(|value| Some(String::from(value))))
|
||||||
.attr("stamp", delay.stamp.clone())
|
.attr("stamp", delay.stamp.clone())
|
||||||
.append(delay.data.clone())
|
.append(delay.data.clone())
|
||||||
.build()
|
.build()
|
||||||
|
|
@ -56,15 +57,17 @@ impl IntoElements for Delay {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::str::FromStr;
|
||||||
use minidom::Element;
|
use minidom::Element;
|
||||||
use error::Error;
|
use error::Error;
|
||||||
|
use jid::Jid;
|
||||||
use delay;
|
use delay;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_simple() {
|
fn test_simple() {
|
||||||
let elem: Element = "<delay xmlns='urn:xmpp:delay' from='capulet.com' stamp='2002-09-10T23:08:25Z'/>".parse().unwrap();
|
let elem: Element = "<delay xmlns='urn:xmpp:delay' from='capulet.com' stamp='2002-09-10T23:08:25Z'/>".parse().unwrap();
|
||||||
let delay = delay::parse_delay(&elem).unwrap();
|
let delay = delay::parse_delay(&elem).unwrap();
|
||||||
assert_eq!(delay.from, Some(String::from("capulet.com")));
|
assert_eq!(delay.from, Some(Jid::from_str("capulet.com").unwrap()));
|
||||||
assert_eq!(delay.stamp, "2002-09-10T23:08:25Z");
|
assert_eq!(delay.stamp, "2002-09-10T23:08:25Z");
|
||||||
assert_eq!(delay.data, None);
|
assert_eq!(delay.data, None);
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +110,7 @@ mod tests {
|
||||||
fn test_serialise_data() {
|
fn test_serialise_data() {
|
||||||
let elem: Element = "<delay xmlns='urn:xmpp:delay' from='juliet@example.org' stamp='2002-09-10T23:08:25Z'>Reason</delay>".parse().unwrap();
|
let elem: Element = "<delay xmlns='urn:xmpp:delay' from='juliet@example.org' stamp='2002-09-10T23:08:25Z'>Reason</delay>".parse().unwrap();
|
||||||
let delay = delay::Delay {
|
let delay = delay::Delay {
|
||||||
from: Some(String::from("juliet@example.org")),
|
from: Some(Jid::from_str("juliet@example.org").unwrap()),
|
||||||
stamp: "2002-09-10T23:08:25Z".to_owned(),
|
stamp: "2002-09-10T23:08:25Z".to_owned(),
|
||||||
data: Some(String::from("Reason")),
|
data: Some(String::from("Reason")),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue