Skip to main content

stomp_agnostic/transport/
mod.rs

1use bytes::Bytes;
2use std::str::Utf8Error;
3use thiserror::Error;
4use winnow::error::{ContextError, ErrMode};
5
6pub(crate) mod client;
7pub(crate) mod server;
8
9/// Data coming down the line from the transport layer. When the transport layer is
10/// e.g. WebSocket, custom data such as Ping/Pong can be handled separately from STOMP data
11/// by using the `Custom` variant.
12#[derive(Debug)]
13pub enum ReadData<T> {
14    Binary(Bytes),
15    Custom(T),
16}
17
18#[derive(Error, Debug)]
19pub enum ReadError {
20    /// This is the most important error to take care of - when the connection has been
21    /// closed, this is the only error that shall be returned when reading. This is so that
22    /// implementors / users of the trait can handle this case consistently.
23    #[error("Connection closed")]
24    ConnectionClosed,
25    #[error("Unexpected message")]
26    UnexpectedMessage,
27    #[error("Parser error")]
28    Parser(ErrMode<ContextError>),
29    #[error(transparent)]
30    Other(#[from] anyhow::Error),
31}
32
33#[derive(Error, Debug)]
34pub enum WriteError {
35    #[error("Utf8Error")]
36    Utf8Error(#[from] Utf8Error),
37    #[error(transparent)]
38    Other(#[from] anyhow::Error),
39}