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
use super::{CloseEvent, Event};
use std::{error, fmt};

macro_rules! err {
    [$kind: ident, $err: expr] => {
        return Err(std::io::Error::new(std::io::ErrorKind::$kind, $err))
    };
    [$err: expr] => {
        return Err(std::io::Error::new(std::io::ErrorKind::Other, $err))
    };
}
pub(crate) use err;

impl error::Error for CloseEvent {}
impl fmt::Display for CloseEvent {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            CloseEvent::Error(msg) => f.write_str(msg),
            CloseEvent::Close { reason, .. } => f.write_str(reason),
        }
    }
}

impl fmt::Display for Event<'_> {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", std::str::from_utf8(self.data()).unwrap_or(""))
    }
}