rss/
textinput.rs

1use quick_xml::{XmlReader, Event, Element};
2
3use fromxml::FromXml;
4use error::Error;
5
6/// A representation of the `<textInput>` element.
7#[derive(Debug, Default, Clone, PartialEq)]
8pub struct TextInput {
9    /// The label of the Submit button for the text input.
10    pub title: String,
11    /// A description of the text input.
12    pub description: String,
13    /// The name of the text object.
14    pub name: String,
15    /// The URL of the CGI script that processes the text input request.
16    pub link: String,
17}
18
19impl FromXml for TextInput {
20    fn from_xml<R: ::std::io::BufRead>(mut reader: XmlReader<R>,
21                                       _: Element)
22                                       -> Result<(Self, XmlReader<R>), Error> {
23        let mut title = None;
24        let mut description = None;
25        let mut name = None;
26        let mut link = None;
27
28        while let Some(e) = reader.next() {
29            match e {
30                Ok(Event::Start(element)) => {
31                    match element.name() {
32                        b"title" => title = element_text!(reader),
33                        b"description" => description = element_text!(reader),
34                        b"name" => name = element_text!(reader),
35                        b"link" => link = element_text!(reader),
36                        _ => skip_element!(reader),
37                    }
38                }
39                Ok(Event::End(_)) => {
40                    let title = title.unwrap_or_default();
41                    let description = description.unwrap_or_default();
42                    let name = name.unwrap_or_default();
43                    let link = link.unwrap_or_default();
44
45                    return Ok((TextInput {
46                        title: title,
47                        description: description,
48                        name: name,
49                        link: link,
50                    }, reader))
51                }
52                Err(err) => return Err(err.into()),
53                _ => {}
54            }
55        }
56
57        Err(Error::EOF)
58    }
59}