http_type/upgrade_type/
impl.rs

1use crate::*;
2
3impl Default for UpgradeType {
4    #[inline]
5    fn default() -> Self {
6        Self::Unknown(String::new())
7    }
8}
9
10impl fmt::Display for UpgradeType {
11    #[inline]
12    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13        match self {
14            UpgradeType::Http => write!(f, "{}", HTTP),
15            UpgradeType::WebSocket => write!(f, "{}", WEBSOCKET),
16            UpgradeType::Unknown(tmp_str) => write!(f, "{}", tmp_str),
17        }
18    }
19}
20
21impl FromStr for UpgradeType {
22    type Err = ();
23
24    #[inline]
25    fn from_str(from_str: &str) -> Result<Self, Self::Err> {
26        match from_str {
27            tmp_from_str if tmp_from_str.eq_ignore_ascii_case(HTTP) => Ok(UpgradeType::Http),
28            tmp_from_str if tmp_from_str.eq_ignore_ascii_case(WEBSOCKET) => {
29                Ok(UpgradeType::WebSocket)
30            }
31            _ => Ok(UpgradeType::Unknown(from_str.to_string())),
32        }
33    }
34}
35
36impl UpgradeType {
37    /// Checks if the current value is `Http`.
38    ///
39    /// - `self` - The current instance of the enum.
40    ///
41    /// - Returns `true` if `self` is `Self::Http`, otherwise `false`.
42    #[inline]
43    pub fn is_http(&self) -> bool {
44        *self == Self::Http
45    }
46
47    /// Checks if the current value is `WebSocket`.
48    ///
49    /// - `self` - The current instance of the enum.
50    ///
51    /// - Returns `true` if `self` is `Self::WebSocket`, otherwise `false`.
52    #[inline]
53    pub fn is_websocket(&self) -> bool {
54        *self == Self::WebSocket
55    }
56
57    /// Checks if the current value is neither `Http` nor `WebSocket`.
58    ///
59    /// - `self` - The current instance of the enum.
60    ///
61    /// - Returns `true` if `self` is neither `Self::Http` nor `Self::WebSocket`, otherwise `false`.
62    #[inline]
63    pub fn is_unknown(&self) -> bool {
64        !self.is_http() && !self.is_websocket()
65    }
66}