Skip to main content

Multistatus

Struct Multistatus 

Source
pub struct Multistatus {
    pub response: Vec<Response>,
}

Fields§

§response: Vec<Response>

Implementations§

Source§

impl Multistatus

Source

pub fn from_xml(xml: &str) -> Result<Self, DeError>

Parse WebDAV multistatus XML from a string

Examples found in repository?
examples/parse.rs (line 35)
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}
Source

pub fn to_xml(&self) -> Result<String, SeError>

Serialize to XML string

Examples found in repository?
examples/parse.rs (line 69)
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 Debug for Multistatus

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Multistatus

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Multistatus

Source§

fn eq(&self, other: &Multistatus) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Multistatus

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Multistatus

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.