@@ -34,18 +34,33 @@ pub enum HttpMethod {
3434}
3535
3636impl HttpMethod {
37- pub fn from_actix_method ( method : & actix_web:: http:: Method ) -> Self {
37+ pub fn is_supported ( method : & actix_web:: http:: Method ) -> bool {
38+ matches ! (
39+ * method,
40+ actix_web:: http:: Method :: GET
41+ | actix_web:: http:: Method :: POST
42+ | actix_web:: http:: Method :: PUT
43+ | actix_web:: http:: Method :: DELETE
44+ | actix_web:: http:: Method :: PATCH
45+ | actix_web:: http:: Method :: HEAD
46+ | actix_web:: http:: Method :: OPTIONS
47+ | actix_web:: http:: Method :: CONNECT
48+ | actix_web:: http:: Method :: TRACE
49+ )
50+ }
51+
52+ pub fn from_actix_method ( method : & actix_web:: http:: Method ) -> Result < Self , & ' static str > {
3853 match * method {
39- actix_web:: http:: Method :: GET => Self :: GET ,
40- actix_web:: http:: Method :: POST => Self :: POST ,
41- actix_web:: http:: Method :: PUT => Self :: PUT ,
42- actix_web:: http:: Method :: DELETE => Self :: DELETE ,
43- actix_web:: http:: Method :: PATCH => Self :: PATCH ,
44- actix_web:: http:: Method :: HEAD => Self :: HEAD ,
45- actix_web:: http:: Method :: OPTIONS => Self :: OPTIONS ,
46- actix_web:: http:: Method :: CONNECT => Self :: CONNECT ,
47- actix_web:: http:: Method :: TRACE => Self :: TRACE ,
48- _ => panic ! ( "Unsupported HTTP method ") ,
54+ actix_web:: http:: Method :: GET => Ok ( Self :: GET ) ,
55+ actix_web:: http:: Method :: POST => Ok ( Self :: POST ) ,
56+ actix_web:: http:: Method :: PUT => Ok ( Self :: PUT ) ,
57+ actix_web:: http:: Method :: DELETE => Ok ( Self :: DELETE ) ,
58+ actix_web:: http:: Method :: PATCH => Ok ( Self :: PATCH ) ,
59+ actix_web:: http:: Method :: HEAD => Ok ( Self :: HEAD ) ,
60+ actix_web:: http:: Method :: OPTIONS => Ok ( Self :: OPTIONS ) ,
61+ actix_web:: http:: Method :: CONNECT => Ok ( Self :: CONNECT ) ,
62+ actix_web:: http:: Method :: TRACE => Ok ( Self :: TRACE ) ,
63+ _ => Err ( "Method Not Allowed ") ,
4964 }
5065 }
5166}
0 commit comments