Skip to main content

contacts_core/
status.rs

1use crate::{
2    ns::*,
3    XmlError,
4    XmlReader,
5    XmlWriter,
6};
7
8#[derive(Debug)]
9pub enum Status {
10    NotFound,
11    Ok,
12}
13
14impl Status {
15    pub fn from_xml(reader: &mut XmlReader) -> Result<Self, XmlError> {
16        reader.open(DAV, "status")?;
17        let status = match reader.text()?.as_str() {
18            "HTTP/1.1 200 OK" =>
19                Status::Ok,
20
21            "HTTP/1.1 404 Not Found" =>
22                Status::NotFound,
23
24            text =>
25                return reader.unexpected_text(text),
26        };
27        reader.close()?;
28        Ok(status)
29    }
30
31    pub fn to_xml(self, writer: &mut XmlWriter) -> Result<(), XmlError> {
32        writer.open_local("status")?;
33
34        match self {
35            Self::NotFound =>
36                writer.text("HTTP/1.1 404 Not Found")?,
37
38            Self::Ok =>
39                writer.text("HTTP/1.1 200 OK")?,
40        }
41        
42        writer.close()
43    }
44}
45