http_type/methods/
impl.rs

1use crate::*;
2use std::fmt::{self, Display};
3
4impl Default for Methods {
5    #[inline]
6    fn default() -> Self {
7        Self::GET
8    }
9}
10
11/// Provides utility methods for the `Methods` type.
12impl Methods {
13    /// Creates a new instance of `Methods` with the default value of `Self::GET`.
14    ///
15    /// This is a shorthand for using the `default` method.
16    #[inline]
17    pub fn new() -> Self {
18        Self::default()
19    }
20
21    /// Checks if the current method is `GET`.
22    ///
23    /// Returns `true` if the method is `GET`, otherwise returns `false`.
24    #[inline]
25    pub fn is_get(&self) -> bool {
26        self.to_owned() == Self::GET.to_owned()
27    }
28
29    /// Checks if the current method is `POST`.
30    ///
31    /// Returns `true` if the method is `POST`, otherwise returns `false`.
32    #[inline]
33    pub fn is_post(&self) -> bool {
34        self.to_owned() == Self::POST.to_owned()
35    }
36}
37
38impl Display for Methods {
39    #[inline]
40    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41        let res: &str = match self {
42            Self::GET => GET,
43            Self::POST => POST,
44        };
45        write!(f, "{}", res)
46    }
47}