socketioxide_emitter/
emit.rs

1use std::fmt;
2
3use crate::Driver;
4
5/// An error that occurs when broadcasting messages.
6pub enum EmitError<D: Driver> {
7    /// The underlying driver error.
8    Driver(D::Error),
9    /// A parsing error that is specific to the parser used.
10    Parser(socketioxide_core::parser::ParserError),
11}
12impl<D: Driver> fmt::Debug for EmitError<D> {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        match self {
15            EmitError::Driver(err) => write!(f, "Driver error: {}", err),
16            EmitError::Parser(err) => write!(f, "Serialization error: {}", err),
17        }
18    }
19}
20impl<D: Driver> fmt::Display for EmitError<D> {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        fmt::Debug::fmt(self, f)
23    }
24}
25impl<D: Driver> std::error::Error for EmitError<D> {}
26
27/// The available socket.io parsers when encoding messages.
28/// Ensure that all your socket.io systems use the same parser.
29#[derive(Debug, Clone, Copy, Default)]
30pub enum Parser {
31    /// Specify the [common socket.io parser](https://docs.rs/socketioxide-parser-common/latest/socketioxide_parser_common/).
32    /// This is the default parser for all socket.io systems.
33    #[cfg(feature = "common-parser")]
34    #[cfg_attr(feature = "common-parser", default)]
35    Common,
36    /// Specify the [msgpack socket.io parser](https://docs.rs/socketioxide-parser-msgpack/latest/socketioxide_parser_msgpack/).
37    /// If you choose to use this parser, ensure that all your socket.io systems support msgpack.
38    #[cfg(feature = "msgpack-parser")]
39    #[cfg_attr(
40        all(feature = "msgpack-parser", not(feature = "common-parser")),
41        default
42    )]
43    MsgPack,
44}