workflow-websocket 0.19.0

WebSocket crate (client and server) providing an async Rust API that functions uniformly in native and in browser (WASM32) environments. This crate allows you to develop WebSocket-driven data exchange that function uniformly in web and desktop applications.
Documentation
//!
//! [`enum@Error`] enum declaration for server-side WebSocket errors.
//!
use thiserror::Error;
use tokio::sync::mpsc::error::SendError;

/// Errors produced by the [`WebSocketServer`](super::WebSocketServer).
#[derive(Debug, Error)]
pub enum Error {
    /// A generic, miscellaneous error carrying a descriptive message.
    #[error("{0}")]
    Other(String),

    /// The server failed to bind and listen on the requested address.
    #[error("{0}")]
    Listen(String),

    /// Indicates that no messages have been received
    /// within the specified timeout period
    #[error("Connection timeout")]
    ConnectionTimeout,

    /// Indicates that the data received is not a
    /// valid handshake message
    #[error("Malformed handshake message")]
    MalformedHandshake,

    /// Indicates that the data received is not a
    /// valid or acceptable message
    #[error("Malformed handshake message")]
    MalformedMessage,

    /// Indicates handler negotiation failure
    /// This error code is reserved for structs
    /// implementing WebSocket handler.
    #[error("Negotiation failure")]
    NegotiationFailure,

    /// Indicates handler negotiation failure
    /// with a specific reason
    /// This error code is reserved for structs
    /// implementing WebSocket handler.
    #[error("Negotiation failure: {0}")]
    NegotiationFailureWithReason(String),

    /// Error sending response via the
    /// tokio MPSC response channel
    #[error("Response channel send error {0:?}")]
    ResponseChannelError(#[from] SendError<tungstenite::Message>),

    /// WebSocket error produced by the underlying
    /// Tungstenite WebSocket crate
    #[error("WebSocket error: {0}")]
    WebSocketError(Box<tungstenite::Error>),

    /// Connection terminated abnormally
    #[error("Connection closed abnormally")]
    AbnormalClose,

    /// Server closed connection
    #[error("Server closed connection")]
    ServerClose,

    /// Failure while signaling the listener to stop.
    #[error("Error signaling listener shutdown: {0}")]
    Stop(String),

    /// Failure while signaling that the listener has finished shutting down.
    #[error("Error signaling listener shutdown: {0}")]
    Done(String),

    /// Failure while waiting for the listener to shut down.
    #[error("Error waiting for listener shutdown: {0}")]
    Join(String),

    /// An underlying I/O error.
    #[error(transparent)]
    IoError(#[from] std::io::Error),
}

impl From<String> for Error {
    fn from(value: String) -> Self {
        Error::Other(value)
    }
}

impl From<tungstenite::Error> for Error {
    fn from(value: tungstenite::Error) -> Self {
        Error::WebSocketError(Box::new(value))
    }
}