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 #[must_use]
27 pub const fn as_str(self) -> &'static str {
28 match self {
29 Self::Get => "GET",
30 Self::Post => "POST",
31 Self::Put => "PUT",
32 Self::Patch => "PATCH",
33 Self::Delete => "DELETE",
34 Self::Head => "HEAD",
35 Self::Options => "OPTIONS",
36 }
37 }
38
39 pub(crate) const fn as_bytes(self) -> &'static [u8] {
40 self.as_str().as_bytes()
41 }
42
43 pub fn from_bytes(value: &[u8]) -> Result<Self, Error> {
49 match value {
50 b"GET" => Ok(Self::Get),
51 b"POST" => Ok(Self::Post),
52 b"PUT" => Ok(Self::Put),
53 b"PATCH" => Ok(Self::Patch),
54 b"DELETE" => Ok(Self::Delete),
55 b"HEAD" => Ok(Self::Head),
56 b"OPTIONS" => Ok(Self::Options),
57 _ => Err(Error::UnsupportedMethod),
58 }
59 }
60}