webdav_request/
method.rs

1#[derive(Clone)]
2enum Inner {
3    Get,
4    Post,
5    Put,
6    Delete,
7    Patch,
8    Propfind,
9    Custom(reqwest::Method),
10}
11#[derive(Clone)]
12pub struct Method(Inner);
13
14impl Method {
15    pub const GET: Method = Method(Inner::Get);
16    pub const POST: Method = Method(Inner::Post);
17    pub const PUT: Method = Method(Inner::Put);
18    pub const DELETE: Method = Method(Inner::Delete);
19    pub const PATCH: Method = Method(Inner::Patch);
20    pub const PROPFIND: Method = Method(Inner::Propfind);
21    pub(crate) fn convert(self) -> reqwest::Method {
22        use reqwest::Method as RMethod;
23        match self.0 {
24            Inner::Get => RMethod::GET,
25            Inner::Post => RMethod::POST,
26            Inner::Put => RMethod::PUT,
27            Inner::Delete => RMethod::DELETE,
28            Inner::Patch => RMethod::PATCH,
29            Inner::Propfind => RMethod::from_bytes("PROPFIND".as_bytes()).unwrap(),
30
31            Inner::Custom(method) => method,
32        }
33    }
34    pub fn from_bytes(src: &[u8]) -> Result<Self, String> {
35        match reqwest::Method::from_bytes(src) {
36            Ok(m) => Ok(Self(Inner::Custom(m))),
37            Err(e) => Err(e.to_string()),
38        }
39    }
40}