diff --git a/src/element.rs b/src/element.rs index 0f63597..661a7e7 100644 --- a/src/element.rs +++ b/src/element.rs @@ -38,6 +38,7 @@ use std::fmt::Debug; use std::marker::PhantomData; use std::ops::Deref; +use std::str::FromStr; use crate::parsers::parse_variable; use crate::types::{Client, Context, Entity, VariableAttr}; @@ -206,6 +207,75 @@ impl Deref for ScanElement { } } +impl From for String { + fn from(scan: ScanElement) -> String { + String::from(&scan.elem) + } +} + +impl From<&ScanElement> for String { + fn from(scan: &ScanElement) -> String { + String::from(&scan.elem) + } +} + +impl From for ScanElement { + fn from(elem: Element) -> ScanElement { + ScanElement::new(elem) + } +} + +impl From for ScanElement { + fn from(elem: Iq) -> ScanElement { + ScanElement::new(elem.into()) + } +} + +impl TryFrom for Iq { + type Error = XMPPParserError; + + fn try_from(scan: ScanElement) -> Result { + scan.elem.try_into() + } +} + +impl From for ScanElement { + fn from(elem: Message) -> ScanElement { + ScanElement::new(elem.into()) + } +} + +impl TryFrom for Message { + type Error = XMPPParserError; + + fn try_from(scan: ScanElement) -> Result { + scan.elem.try_into() + } +} + +impl From for ScanElement { + fn from(elem: Presence) -> ScanElement { + ScanElement::new(elem.into()) + } +} + +impl TryFrom for Presence { + type Error = XMPPParserError; + + fn try_from(scan: ScanElement) -> Result { + scan.elem.try_into() + } +} + +impl FromStr for ScanElement { + type Err = MinidomError; + + fn from_str(s: &str) -> Result { + let elem = s.parse::()?; + Ok(ScanElement::new(elem)) + } +} + fn apply_context(mut elem: Element, context: &Context) -> Element { // Parse variables in attributes. for (_attr, val) in elem.attrs_mut() {