http_request/websocket/websocket/
trait.rs

1use crate::*;
2
3pub trait WebSocketTrait: Send + Sync {
4    fn send_text(&mut self, text: &str) -> WebSocketResult;
5    fn send_binary(&mut self, data: &[u8]) -> WebSocketResult;
6    fn send_ping(&mut self, data: &[u8]) -> WebSocketResult;
7    fn send_pong(&mut self, data: &[u8]) -> WebSocketResult;
8    fn receive(&mut self) -> WebSocketMessageResult;
9    fn close(&mut self) -> WebSocketResult;
10    fn is_connected(&self) -> bool;
11}
12
13pub trait AsyncWebSocketTrait: Send + Sync {
14    fn send_text<'a>(
15        &'a mut self,
16        text: &'a str,
17    ) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>;
18    fn send_binary<'a>(
19        &'a mut self,
20        data: &'a [u8],
21    ) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>;
22    fn send_ping<'a>(
23        &'a mut self,
24        data: &'a [u8],
25    ) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>;
26    fn send_pong<'a>(
27        &'a mut self,
28        data: &'a [u8],
29    ) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>;
30    fn receive<'a>(
31        &'a mut self,
32    ) -> Pin<Box<dyn Future<Output = WebSocketMessageResult> + Send + 'a>>;
33    fn close<'a>(&'a mut self) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>;
34    fn is_connected(&self) -> bool;
35}