1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
mod errors;
mod frame;
mod mask;
mod utils;
mod ws;
pub mod handshake;
pub mod http;
pub use frame::*;
pub use ws::*;
use errors::*;
use mask::*;
use utils::*;
use std::io::Result;
use tokio::{
io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader},
net::TcpStream,
};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum DataType {
Text,
Binary,
}
#[derive(Debug, Clone)]
pub enum Event<'a> {
Ping(&'a [u8]),
Pong(&'a [u8]),
}
impl Event<'_> {
#[inline]
pub fn data(&self) -> &[u8] {
match self {
Event::Ping(data) => data,
Event::Pong(data) => data,
}
}
}
impl std::fmt::Display for Event<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", std::str::from_utf8(self.data()).unwrap_or(""))
}
}