rss/
source.rs

1use quick_xml::{XmlReader, Element};
2
3use fromxml::FromXml;
4use error::Error;
5
6/// A representation of the `<source>` element.
7#[derive(Debug, Default, Clone, PartialEq)]
8pub struct Source {
9    /// The URL of the source.
10    pub url: String,
11    /// The title of the source.
12    pub title: Option<String>,
13}
14
15impl FromXml for Source {
16    fn from_xml<R: ::std::io::BufRead>(mut reader: XmlReader<R>,
17                                       element: Element)
18                                       -> Result<(Self, XmlReader<R>), Error> {
19        let mut url = None;
20
21        for attr in element.attributes().with_checks(false).unescaped() {
22            if let Ok(attr) = attr {
23                if attr.0 == b"url" {
24                    url = Some(try!(String::from_utf8(attr.1.into_owned())));
25                    break;
26                }
27            }
28        }
29
30        let url = url.unwrap_or_default();
31        let content = element_text!(reader);
32
33        Ok((Source {
34            url: url,
35            title: content,
36        }, reader))
37    }
38}