sark_http/method/
known.rs1#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
2#[repr(u8)]
3pub enum Known {
4 Get,
5 Post,
6 Put,
7 Patch,
8 Delete,
9 Head,
10 Options,
11 Connect,
12}
13
14impl Known {
15 pub const ALL: u8 = u8::MAX;
16
17 #[doc(hidden)]
18 pub const fn bit(self) -> u8 {
19 1 << self as u8
20 }
21
22 pub const fn as_str(&self) -> &str {
23 match self {
24 Self::Get => "GET",
25 Self::Post => "POST",
26 Self::Put => "PUT",
27 Self::Patch => "PATCH",
28 Self::Delete => "DELETE",
29 Self::Head => "HEAD",
30 Self::Options => "OPTIONS",
31 Self::Connect => "CONNECT",
32 }
33 }
34
35 pub(crate) fn from_bytes(bytes: &[u8]) -> Option<Self> {
36 match bytes {
37 b"GET" => Some(Self::Get),
38 b"POST" => Some(Self::Post),
39 b"PUT" => Some(Self::Put),
40 b"PATCH" => Some(Self::Patch),
41 b"DELETE" => Some(Self::Delete),
42 b"HEAD" => Some(Self::Head),
43 b"OPTIONS" => Some(Self::Options),
44 b"CONNECT" => Some(Self::Connect),
45 _ => None,
46 }
47 }
48}
49
50const _: () = assert!(core::mem::size_of::<Known>() == 1);
51const _: () = assert!(core::mem::size_of::<Option<Known>>() == 1);