pub struct Response {
pub href: String,
pub propstat: PropStat,
}Fields§
§href: String§propstat: PropStatImplementations§
Source§impl Response
impl Response
Sourcepub fn is_collection(&self) -> bool
pub fn is_collection(&self) -> bool
Check if this response represents a collection (directory)
Examples found in repository?
examples/parse.rs (line 43)
3fn main() {
4 let xml = r#"<?xml version="1.0" encoding="utf-8"?>
5<D:multistatus xmlns:D="DAV:">
6 <D:response>
7 <D:href>/documents/</D:href>
8 <D:propstat>
9 <D:prop>
10 <D:displayname>Documents</D:displayname>
11 <D:getlastmodified>Mon, 13 Nov 2023 14:52:27 GMT</D:getlastmodified>
12 <D:resourcetype>
13 <D:collection />
14 </D:resourcetype>
15 </D:prop>
16 <D:status>HTTP/1.1 200 OK</D:status>
17 </D:propstat>
18 </D:response>
19 <D:response>
20 <D:href>/documents/report.pdf</D:href>
21 <D:propstat>
22 <D:prop>
23 <D:displayname>report.pdf</D:displayname>
24 <D:getcontentlength>524288</D:getcontentlength>
25 <D:getcontenttype>application/pdf</D:getcontenttype>
26 <D:getlastmodified>Tue, 14 Nov 2023 10:30:00 GMT</D:getlastmodified>
27 <D:resourcetype></D:resourcetype>
28 </D:prop>
29 <D:status>HTTP/1.1 200 OK</D:status>
30 </D:propstat>
31 </D:response>
32</D:multistatus>"#;
33
34 // Parse the XML
35 let multistatus = Multistatus::from_xml(xml).expect("Failed to parse XML");
36
37 println!("WebDAV Response Summary");
38 println!("=======================\n");
39
40 for response in &multistatus.response {
41 println!("Resource: {}", response.href);
42 println!(" Name: {}", response.name());
43 println!(" Type: {}", if response.is_collection() { "Directory" } else { "File" });
44
45 let prop = &response.propstat.prop;
46
47 if let Some(display_name) = &prop.displayname {
48 println!(" Display Name: {}", display_name);
49 }
50
51 if let Some(size) = prop.getcontentlength {
52 println!(" Size: {} bytes ({:.2} KB)", size, size as f64 / 1024.0);
53 }
54
55 if let Some(content_type) = &prop.getcontenttype {
56 println!(" Content Type: {}", content_type);
57 }
58
59 if let Some(modified) = &prop.getlastmodified {
60 println!(" Last Modified: {}", modified);
61 }
62
63 println!();
64 }
65
66 // Demonstrate serialization
67 println!("\nSerialized back to XML:");
68 println!("=======================");
69 match multistatus.to_xml() {
70 Ok(xml_output) => println!("{}", xml_output),
71 Err(e) => eprintln!("Failed to serialize: {}", e),
72 }
73}Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Get the file/directory name from href
Examples found in repository?
examples/parse.rs (line 42)
3fn main() {
4 let xml = r#"<?xml version="1.0" encoding="utf-8"?>
5<D:multistatus xmlns:D="DAV:">
6 <D:response>
7 <D:href>/documents/</D:href>
8 <D:propstat>
9 <D:prop>
10 <D:displayname>Documents</D:displayname>
11 <D:getlastmodified>Mon, 13 Nov 2023 14:52:27 GMT</D:getlastmodified>
12 <D:resourcetype>
13 <D:collection />
14 </D:resourcetype>
15 </D:prop>
16 <D:status>HTTP/1.1 200 OK</D:status>
17 </D:propstat>
18 </D:response>
19 <D:response>
20 <D:href>/documents/report.pdf</D:href>
21 <D:propstat>
22 <D:prop>
23 <D:displayname>report.pdf</D:displayname>
24 <D:getcontentlength>524288</D:getcontentlength>
25 <D:getcontenttype>application/pdf</D:getcontenttype>
26 <D:getlastmodified>Tue, 14 Nov 2023 10:30:00 GMT</D:getlastmodified>
27 <D:resourcetype></D:resourcetype>
28 </D:prop>
29 <D:status>HTTP/1.1 200 OK</D:status>
30 </D:propstat>
31 </D:response>
32</D:multistatus>"#;
33
34 // Parse the XML
35 let multistatus = Multistatus::from_xml(xml).expect("Failed to parse XML");
36
37 println!("WebDAV Response Summary");
38 println!("=======================\n");
39
40 for response in &multistatus.response {
41 println!("Resource: {}", response.href);
42 println!(" Name: {}", response.name());
43 println!(" Type: {}", if response.is_collection() { "Directory" } else { "File" });
44
45 let prop = &response.propstat.prop;
46
47 if let Some(display_name) = &prop.displayname {
48 println!(" Display Name: {}", display_name);
49 }
50
51 if let Some(size) = prop.getcontentlength {
52 println!(" Size: {} bytes ({:.2} KB)", size, size as f64 / 1024.0);
53 }
54
55 if let Some(content_type) = &prop.getcontenttype {
56 println!(" Content Type: {}", content_type);
57 }
58
59 if let Some(modified) = &prop.getlastmodified {
60 println!(" Last Modified: {}", modified);
61 }
62
63 println!();
64 }
65
66 // Demonstrate serialization
67 println!("\nSerialized back to XML:");
68 println!("=======================");
69 match multistatus.to_xml() {
70 Ok(xml_output) => println!("{}", xml_output),
71 Err(e) => eprintln!("Failed to serialize: {}", e),
72 }
73}Trait Implementations§
Source§impl<'de> Deserialize<'de> for Response
impl<'de> Deserialize<'de> for Response
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Response
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnsafeUnpin for Response
impl UnwindSafe for Response
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more