rss/
cloud.rs

1use quick_xml::{XmlReader, Element};
2
3use fromxml::FromXml;
4use error::Error;
5
6/// A representation of the `<cloud>` element.
7#[derive(Debug, Default, Clone, PartialEq)]
8pub struct Cloud {
9    /// The domain to register with.
10    pub domain: String,
11    /// The port to register with.
12    pub port: String,
13    /// The path to register with.
14    pub path: String,
15    /// The procedure to register with.
16    pub register_procedure: String,
17    /// The protocol to register with.
18    pub protocol: String,
19}
20
21impl FromXml for Cloud {
22    fn from_xml<R: ::std::io::BufRead>(mut reader: XmlReader<R>,
23                                       element: Element)
24                                       -> Result<(Self, XmlReader<R>), Error> {
25        let mut domain = None;
26        let mut port = None;
27        let mut path = None;
28        let mut register_procedure = None;
29        let mut protocol = None;
30
31        for attr in element.attributes().with_checks(false).unescaped() {
32            if let Ok(attr) = attr {
33                match attr.0 {
34                    b"domain" if domain.is_none() => {
35                        domain = Some(try!(String::from_utf8(attr.1.into_owned())));
36                    }
37                    b"port" if port.is_none() => {
38                        port = Some(try!(String::from_utf8(attr.1.into_owned())));
39                    }
40                    b"path" if path.is_none() => {
41                        path = Some(try!(String::from_utf8(attr.1.into_owned())));
42                    }
43                    b"registerProcedure" if register_procedure.is_none() => {
44                        register_procedure = Some(try!(String::from_utf8(attr.1.into_owned())));
45                    }
46                    b"protocol" if protocol.is_none() => {
47                        protocol = Some(try!(String::from_utf8(attr.1.into_owned())));
48                    }
49                    _ => {}
50                }
51            }
52        }
53
54        skip_element!(reader);
55
56        let domain = domain.unwrap_or_default();
57        let port = port.unwrap_or_default();
58        let path = path.unwrap_or_default();
59        let register_procedure = register_procedure.unwrap_or_default();
60        let protocol = protocol.unwrap_or_default();
61
62        Ok((Cloud {
63            domain: domain,
64            port: port,
65            path: path,
66            register_procedure: register_procedure,
67            protocol: protocol,
68        }, reader))
69
70    }
71}