rss/
guid.rs

1use quick_xml::{XmlReader, Element};
2
3use fromxml::FromXml;
4use error::Error;
5
6/// A representation of the `<guid>` element.
7#[derive(Debug, Clone, PartialEq)]
8pub struct Guid {
9    /// The value of the GUID.
10    pub value: String,
11    /// Indicates if the GUID is a permalink.
12    pub is_permalink: bool,
13}
14
15impl Default for Guid {
16    #[inline]
17    fn default() -> Self {
18        Guid {
19            value: Default::default(),
20            is_permalink: true,
21        }
22    }
23}
24
25impl FromXml for Guid {
26    fn from_xml<R: ::std::io::BufRead>(mut reader: XmlReader<R>,
27                                       element: Element)
28                                       -> Result<(Self, XmlReader<R>), Error> {
29        let mut is_permalink = true;
30
31        for attr in element.attributes().with_checks(false).unescaped() {
32            if let Ok(attr) = attr {
33                if attr.0 == b"isPermaLink" {
34                    is_permalink = &attr.1 as &[u8] != b"false";
35                    break;
36                }
37            }
38        }
39
40        let content = element_text!(reader).unwrap_or_default();
41
42        Ok((Guid {
43            value: content,
44            is_permalink: is_permalink,
45        }, reader))
46    }
47}