1use crate::Error;
4
5#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7pub enum Method {
8 Get,
10 Post,
12 Put,
14 Patch,
16 Delete,
18 Head,
20 Options,
22}
23
24impl Method {
25 pub(crate) const fn as_bytes(self) -> &'static [u8] {
26 match self {
27 Self::Get => b"GET",
28 Self::Post => b"POST",
29 Self::Put => b"PUT",
30 Self::Patch => b"PATCH",
31 Self::Delete => b"DELETE",
32 Self::Head => b"HEAD",
33 Self::Options => b"OPTIONS",
34 }
35 }
36
37 pub(crate) fn from_bytes(value: &[u8]) -> Result<Self, Error> {
38 match value {
39 b"GET" => Ok(Self::Get),
40 b"POST" => Ok(Self::Post),
41 b"PUT" => Ok(Self::Put),
42 b"PATCH" => Ok(Self::Patch),
43 b"DELETE" => Ok(Self::Delete),
44 b"HEAD" => Ok(Self::Head),
45 b"OPTIONS" => Ok(Self::Options),
46 _ => Err(Error::UnsupportedMethod),
47 }
48 }
49}