http_type/upgrade_type/
impl.rs1use 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, "{}", WEBSOCKE),
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(WEBSOCKE) => {
29 Ok(UpgradeType::WebSocket)
30 }
31 _ => Ok(UpgradeType::Unknown(from_str.to_string())),
32 }
33 }
34}
35
36impl UpgradeType {
37 #[inline]
38 pub fn is_websocket(&self) -> bool {
39 *self == Self::WebSocket
40 }
41
42 #[inline]
43 pub fn is_http(&self) -> bool {
44 *self == Self::Http
45 }
46}