web_socket_io/
error.rs

1use std::fmt;
2
3/// Represents a connection closure with a code and reason.
4#[derive(Debug)]
5pub struct ConnClose {
6    /// represents the status code of the close event.
7    pub code: u16,
8    /// represents the reason for the close event
9    pub reason: Box<str>,
10}
11
12impl fmt::Display for ConnClose {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        write!(f, "{}", self.reason)
15    }
16}
17
18impl std::error::Error for ConnClose {}
19
20/// Errors that can occur during notification.
21#[derive(Debug)]
22pub enum NotifyError {
23    /// The event name exceeds the allowed size (255 bytes).
24    EventNameTooBig,
25    /// The receiver channel has been closed.
26    ReceiverClosed,
27}
28
29impl fmt::Display for NotifyError {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        match self {
32            NotifyError::EventNameTooBig => write!(f, "event name exceeds the allowed length."),
33            NotifyError::ReceiverClosed => write!(f, "receiver is already closed."),
34        }
35    }
36}
37
38impl std::error::Error for NotifyError {}
39
40
41/// Indicates that the receiver half is closed.
42#[derive(Debug)]
43pub struct ReceiverClosed;
44
45impl fmt::Display for ReceiverClosed {
46    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47        write!(f, "receiver is already closed.")
48    }
49}
50impl std::error::Error for ReceiverClosed {}