webdav_xml/properties/
getcontentlength.rs

1// SPDX-FileCopyrightText: d-k-bo <d-k-bo@mailbox.org>
2//
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5use crate::{Element, Error, Value, DAV_NAMESPACE, DAV_PREFIX};
6
7/// The `getcontentlength` property as defined in
8/// [RFC 4918](http://webdav.org/specs/rfc4918.html#PROPERTY_getcontentlength).
9#[derive(Clone, Copy, Debug, PartialEq)]
10pub struct ContentLength(pub u64);
11
12impl Element for ContentLength {
13    const NAMESPACE: &'static str = DAV_NAMESPACE;
14    const PREFIX: &'static str = DAV_PREFIX;
15    const LOCAL_NAME: &'static str = "getcontentlength";
16}
17
18impl TryFrom<&Value> for ContentLength {
19    type Error = Error;
20
21    fn try_from(value: &Value) -> Result<Self, Self::Error> {
22        value.to_str()?.parse().map(Self).map_err(Error::other)
23    }
24}
25
26impl From<ContentLength> for Value {
27    fn from(ContentLength(len): ContentLength) -> Value {
28        len.to_string().into()
29    }
30}