graphql_ws_client_old_protocol/
native.rs

1use crate::websockets::WebsocketMessage;
2
3impl WebsocketMessage for async_tungstenite::tungstenite::Message {
4    type Error = async_tungstenite::tungstenite::Error;
5
6    fn new(text: String) -> Self {
7        async_tungstenite::tungstenite::Message::Text(text)
8    }
9
10    fn text(&self) -> Option<&str> {
11        match self {
12            async_tungstenite::tungstenite::Message::Text(text) => Some(text.as_ref()),
13            _ => None,
14        }
15    }
16
17    fn error_message(&self) -> Option<String> {
18        match self {
19            async_tungstenite::tungstenite::Message::Close(Some(frame)) => {
20                Some(frame.reason.to_string())
21            }
22            _ => None,
23        }
24    }
25
26    fn is_ping(&self) -> bool {
27        matches!(self, async_tungstenite::tungstenite::Message::Ping(_))
28    }
29
30    fn is_pong(&self) -> bool {
31        matches!(self, async_tungstenite::tungstenite::Message::Pong(_))
32    }
33
34    fn is_close(&self) -> bool {
35        matches!(self, async_tungstenite::tungstenite::Message::Close(_))
36    }
37}