element: Add conversions from/to ScanElement
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
d4a8719e09
commit
f9539f92f0
1 changed files with 70 additions and 0 deletions
|
@ -38,6 +38,7 @@
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use crate::parsers::parse_variable;
|
use crate::parsers::parse_variable;
|
||||||
use crate::types::{Client, Context, Entity, VariableAttr};
|
use crate::types::{Client, Context, Entity, VariableAttr};
|
||||||
|
@ -206,6 +207,75 @@ impl Deref for ScanElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ScanElement> 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<Element> for ScanElement {
|
||||||
|
fn from(elem: Element) -> ScanElement {
|
||||||
|
ScanElement::new(elem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Iq> for ScanElement {
|
||||||
|
fn from(elem: Iq) -> ScanElement {
|
||||||
|
ScanElement::new(elem.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<ScanElement> for Iq {
|
||||||
|
type Error = XMPPParserError;
|
||||||
|
|
||||||
|
fn try_from(scan: ScanElement) -> Result<Iq, Self::Error> {
|
||||||
|
scan.elem.try_into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Message> for ScanElement {
|
||||||
|
fn from(elem: Message) -> ScanElement {
|
||||||
|
ScanElement::new(elem.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<ScanElement> for Message {
|
||||||
|
type Error = XMPPParserError;
|
||||||
|
|
||||||
|
fn try_from(scan: ScanElement) -> Result<Message, Self::Error> {
|
||||||
|
scan.elem.try_into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Presence> for ScanElement {
|
||||||
|
fn from(elem: Presence) -> ScanElement {
|
||||||
|
ScanElement::new(elem.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<ScanElement> for Presence {
|
||||||
|
type Error = XMPPParserError;
|
||||||
|
|
||||||
|
fn try_from(scan: ScanElement) -> Result<Presence, Self::Error> {
|
||||||
|
scan.elem.try_into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for ScanElement {
|
||||||
|
type Err = MinidomError;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
let elem = s.parse::<Element>()?;
|
||||||
|
Ok(ScanElement::new(elem))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn apply_context(mut elem: Element, context: &Context) -> Element {
|
fn apply_context(mut elem: Element, context: &Context) -> Element {
|
||||||
// Parse variables in attributes.
|
// Parse variables in attributes.
|
||||||
for (_attr, val) in elem.attrs_mut() {
|
for (_attr, val) in elem.attrs_mut() {
|
||||||
|
|
Loading…
Reference in a new issue