1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/// Represents the set of supported HTTP methods.
///
/// This enum provides a simplified and strongly typed representation
/// of common HTTP request methods.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Method {
/// The HTTP GET method.
GET,
/// The HTTP POST method.
POST,
/// The HTTP PUT method.
PUT,
/// The HTTP DELETE method.
DELETE,
/// The HTTP PATCH method.
PATCH,
/// The HTTP OPTIONS method.
OPTIONS,
/// The HTTP HEAD method.
HEAD,
}
impl Method {
/// Converts a reference to an `http::Method` into a corresponding `Method` variant.
///
/// # Arguments
///
/// * `method` - A reference to an `http::Method` from the `http` crate.
///
/// # Returns
///
/// A `Method` variant matching the input. If the method is not recognized,
/// it defaults to `Method::GET`.
///
/// # Example
///
/// ```
/// use http::Method as HyperMethod;
/// use velto::http_method::Method;
///
/// let method = Method::from_hyper(&HyperMethod::POST);
/// assert_eq!(method, Method::POST);
/// ```
pub fn from_hyper(method: &http::Method) -> Self {
match *method {
http::Method::GET => Method::GET,
http::Method::POST => Method::POST,
http::Method::PUT => Method::PUT,
http::Method::DELETE => Method::DELETE,
http::Method::PATCH => Method::PATCH,
http::Method::OPTIONS => Method::OPTIONS,
http::Method::HEAD => Method::HEAD,
_ => Method::GET, // fallback
}
}
}