data_forms, media_element: Implement forgotten serialisation.

This commit is contained in:
Emmanuel Gil Peyrot 2017-05-25 01:00:17 +01:00
commit f08c81382c
2 changed files with 118 additions and 2 deletions

View file

@ -6,7 +6,7 @@
use std::convert::TryFrom;
use minidom::Element;
use minidom::{Element, IntoElements, ElementEmitter};
use error::Error;
@ -18,6 +18,22 @@ pub struct URI {
pub uri: String,
}
impl From<URI> for Element {
fn from(uri: URI) -> Element {
Element::builder("uri")
.ns(ns::MEDIA_ELEMENT)
.attr("type", uri.type_)
.append(uri.uri)
.build()
}
}
impl IntoElements for URI {
fn into_elements(self, emitter: &mut ElementEmitter) {
emitter.append_child(self.into());
}
}
#[derive(Debug, Clone)]
pub struct MediaElement {
pub width: Option<usize>,
@ -54,6 +70,23 @@ impl TryFrom<Element> for MediaElement {
}
}
impl From<MediaElement> for Element {
fn from(media: MediaElement) -> Element {
Element::builder("media")
.ns(ns::MEDIA_ELEMENT)
.attr("width", media.width)
.attr("height", media.height)
.append(media.uris)
.build()
}
}
impl IntoElements for MediaElement {
fn into_elements(self, emitter: &mut ElementEmitter) {
emitter.append_child(self.into());
}
}
#[cfg(test)]
mod tests {
use super::*;