webdav_xml/elements/
href.rs1use std::str::FromStr;
6
7use crate::{value::Value, Element, Error, DAV_NAMESPACE, DAV_PREFIX};
8
9#[derive(Clone, Debug, PartialEq)]
11pub struct Href(pub http::Uri);
12
13impl Element for Href {
14 const NAMESPACE: &'static str = DAV_NAMESPACE;
15 const PREFIX: &'static str = DAV_PREFIX;
16 const LOCAL_NAME: &'static str = "href";
17}
18
19impl TryFrom<&Value> for Href {
20 type Error = Error;
21
22 fn try_from(value: &Value) -> Result<Self, Self::Error> {
23 Ok(Self(value.to_str()?.parse().map_err(Error::other)?))
24 }
25}
26
27impl From<Href> for Value {
28 fn from(Href(uri): Href) -> Value {
29 Value::Text(uri.to_string().into())
30 }
31}
32
33impl From<http::Uri> for Href {
34 fn from(uri: http::Uri) -> Self {
35 Href(uri)
36 }
37}
38
39impl FromStr for Href {
40 type Err = <http::Uri as FromStr>::Err;
41
42 fn from_str(s: &str) -> Result<Self, Self::Err> {
43 http::Uri::from_str(s).map(Href)
44 }
45}