From 5bd0feb17852e0113ec9263a7503d148f519d4d4 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 29 Jul 2017 05:11:30 +0100 Subject: [PATCH] optionally implement minidom::IntoAttributeValue --- Cargo.toml | 1 + src/lib.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 715fc128..97c9cf5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ license = "LGPL-3.0+" gitlab = { repository = "lumi/jid-rs" } [dependencies] +minidom = { version = "0.4.4", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 3f39cbcf..30ba7f7a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -359,6 +359,19 @@ impl Jid { } +#[cfg(feature = "minidom")] +extern crate minidom; + +#[cfg(feature = "minidom")] +use minidom::IntoAttributeValue; + +#[cfg(feature = "minidom")] +impl IntoAttributeValue for Jid { + fn into_attribute_value(self) -> Option { + Some(String::from(self)) + } +} + #[cfg(test)] mod tests { use super::*; @@ -380,4 +393,12 @@ mod tests { fn serialise() { assert_eq!(String::from(Jid::full("a", "b", "c")), String::from("a@b/c")); } + + #[cfg(feature = "minidom")] + #[test] + fn minidom() { + let elem: minidom::Element = "".parse().unwrap(); + let to: Jid = elem.attr("from").unwrap().parse().unwrap(); + assert_eq!(to, Jid::full("a", "b", "c")); + } }