http_type/upgrade_type/
impl.rs

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