webdav_headers/
destination.rs1use crate::{utils::HeaderIteratorExt, DESTINATION};
6
7#[derive(Clone, Debug, PartialEq)]
9pub struct Destination(pub http::Uri);
10
11impl headers::Header for Destination {
12 fn name() -> &'static http::HeaderName {
13 &DESTINATION
14 }
15 fn decode<'i, I>(values: &mut I) -> Result<Self, headers::Error>
16 where
17 Self: Sized,
18 I: Iterator<Item = &'i http::HeaderValue>,
19 {
20 Ok(Self(
21 values
22 .extract_str()?
23 .parse()
24 .map_err(|_| headers::Error::invalid())?,
25 ))
26 }
27 fn encode<E: Extend<http::HeaderValue>>(&self, values: &mut E) {
28 values.extend(std::iter::once(self.0.to_string().parse().unwrap()))
29 }
30}
31
32#[cfg(test)]
33#[test]
34fn test() {
35 use crate::test::test_all;
36
37 test_all([
38 (
39 "https://example.com/foo",
40 Destination("https://example.com/foo".parse().unwrap()),
41 ),
42 ("/foo/bar/123", Destination("/foo/bar/123".parse().unwrap())),
43 ])
44}