torus_http/method.rs
1//! Contains safe wrappers for http methods, note that the conversion is case insensitive so custom methods might not behave as expected
2//!
3//! # example:
4//!
5//! ```rust
6//! assert_eq!(HttpMethod::Get, HttpMethod::from_str("GET"));
7//! ```
8//!
9//! ## Note!!!
10//!
11//! due to how it is written right now, you cannot get a custom overwrite for the method (TODO: rephrase this I apparently don't know english)
12//!
13//! ```rust
14//! assert_eq!(HttpMethod::Other("GET"), HttpMethod::from_str("GET")); // this does not hold
15//! ```
16
17impl HttpMethod {
18 /// Generate an http method from a string
19 #[must_use]
20 pub fn from_str_val(s: &str) -> Self {
21 match s.to_lowercase().as_str() {
22 "get" => HttpMethod::Get,
23 "post" => HttpMethod::Post,
24 "update" => HttpMethod::Update,
25 "delete" => HttpMethod::Delete,
26 "put" => HttpMethod::Put,
27 "patch" => HttpMethod::Patch,
28 "head" => HttpMethod::Head,
29 "options" => HttpMethod::Options,
30 other => HttpMethod::Other(other.to_string()),
31 }
32 }
33}
34
35/// Enum covering most standard http methods and also allowing for custom ones
36#[derive(Debug, Clone, Eq, PartialEq, Hash)]
37pub enum HttpMethod {
38 Get,
39 Post,
40 Delete,
41 Update,
42 Put,
43 Patch,
44 Head,
45 Options,
46 Other(String),
47}