use quick_xml::{XmlReader, Element};
use fromxml::FromXml;
use error::Error;
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Enclosure {
pub url: String,
pub length: String,
pub mime_type: String,
}
impl FromXml for Enclosure {
fn from_xml<R: ::std::io::BufRead>(mut reader: XmlReader<R>,
element: Element)
-> Result<(Self, XmlReader<R>), Error> {
let mut url = None;
let mut length = None;
let mut mime_type = None;
for attr in element.attributes().with_checks(false).unescaped() {
if let Ok(attr) = attr {
match attr.0 {
b"url" if url.is_none() => {
url = Some(try!(String::from_utf8(attr.1.into_owned())));
}
b"length" if length.is_none() => {
length = Some(try!(String::from_utf8(attr.1.into_owned())));
}
b"type" if mime_type.is_none() => {
mime_type = Some(try!(String::from_utf8(attr.1.into_owned())));
}
_ => {}
}
}
}
skip_element!(reader);
let url = url.unwrap_or_default();
let length = length.unwrap_or_default();
let mime_type = mime_type.unwrap_or_default();
Ok((Enclosure {
url: url,
length: length,
mime_type: mime_type,
}, reader))
}
}