http_type/upgrade_type/
impl.rs1use 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 pub fn is_http(&self) -> bool {
38 *self == Self::Http
39 }
40
41 pub fn is_websocket(&self) -> bool {
47 *self == Self::WebSocket
48 }
49
50 pub fn is_unknown(&self) -> bool {
56 !self.is_http() && !self.is_websocket()
57 }
58}