From 7b6d444f034f0b67a5f47737f51b8b381e0a977e Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 1 May 2017 01:50:18 +0100 Subject: [PATCH] delay: Use Jid for from attribute. --- src/delay.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/delay.rs b/src/delay.rs index 8e8e382e..06c980f6 100644 --- a/src/delay.rs +++ b/src/delay.rs @@ -8,12 +8,13 @@ use minidom::{Element, IntoElements}; use minidom::convert::ElementEmitter; use error::Error; +use jid::Jid; use ns; #[derive(Debug, Clone)] pub struct Delay { - pub from: Option, + pub from: Option, pub stamp: String, pub data: Option, } @@ -41,7 +42,7 @@ pub fn parse_delay(root: &Element) -> Result { pub fn serialise(delay: &Delay) -> Element { Element::builder("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()) .append(delay.data.clone()) .build() @@ -56,15 +57,17 @@ impl IntoElements for Delay { #[cfg(test)] mod tests { + use std::str::FromStr; use minidom::Element; use error::Error; + use jid::Jid; use delay; #[test] fn test_simple() { let elem: Element = "".parse().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.data, None); } @@ -107,7 +110,7 @@ mod tests { fn test_serialise_data() { let elem: Element = "Reason".parse().unwrap(); 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(), data: Some(String::from("Reason")), };