1use melodium_core::{executive::*, *};
2use melodium_macro::{mel_data, mel_function};
3use trillium::Method;
4
5#[mel_data(traits(ToString PartialEquality Equality Display))]
10#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
11pub struct HttpMethod(pub Method);
12
13impl ToString for HttpMethod {
14 fn to_string(&self) -> String {
15 self.0.to_string()
16 }
17}
18
19impl Display for HttpMethod {
20 fn display(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
21 write!(f, "{}", melodium_core::executive::ToString::to_string(self))
22 }
23}
24
25#[mel_function]
29pub fn method(name: string) -> Option<HttpMethod> {
30 match Method::try_from(name.as_str()) {
31 Ok(method) => Some(HttpMethod(method)),
32 Err(_) => None,
33 }
34}
35
36#[mel_function]
38pub fn delete() -> HttpMethod {
39 HttpMethod(Method::Delete)
40}
41
42#[mel_function]
44pub fn get() -> HttpMethod {
45 HttpMethod(Method::Get)
46}
47
48#[mel_function]
50pub fn head() -> HttpMethod {
51 HttpMethod(Method::Head)
52}
53
54#[mel_function]
56pub fn options() -> HttpMethod {
57 HttpMethod(Method::Options)
58}
59
60#[mel_function]
62pub fn patch() -> HttpMethod {
63 HttpMethod(Method::Patch)
64}
65
66#[mel_function]
68pub fn post() -> HttpMethod {
69 HttpMethod(Method::Post)
70}
71
72#[mel_function]
74pub fn put() -> HttpMethod {
75 HttpMethod(Method::Put)
76}
77
78#[mel_function]
80pub fn trace() -> HttpMethod {
81 HttpMethod(Method::Trace)
82}