symqtt 0.1.1

Synchronous MQTT 3.1.1/5.0 client — blocking API, no async runtime
Documentation
//! Client-level error types for MQTT 3.1.1 operations

use symqtt_codec::v3::ConnectReturnCode;

use crate::v3::SessionError;

/// Errors produced by [`Client`](super::Client) operations
#[non_exhaustive]
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// Broker rejected the CONNECT request with a non-zero return code
    #[error("connection refused: {0:?}")]
    ConnectRefused(ConnectReturnCode),
    /// Transport-level I/O failure
    #[error("transport I/O: {0}")]
    Io(#[from] std::io::Error),
    /// Failed to decode an inbound packet
    #[error("decode: {0}")]
    Decode(#[from] symqtt_codec::DecodeError),
    /// Failed to encode an outbound packet
    #[error("encode: {0}")]
    Encode(#[from] symqtt_codec::EncodeError),
    /// All packet IDs in the inflight window are occupied
    #[error("inflight window full")]
    WindowFull,
    /// Operation timed out waiting for a response
    #[error("ack timeout")]
    Timeout,
    /// Connection is closed or was never established
    #[error("disconnected")]
    Disconnected,
    /// Broker did not respond to PINGREQ within the configured timeout
    #[error("ping timeout")]
    PingTimeout,
    /// Session state machine encountered an invalid transition
    #[error("session: {0}")]
    Session(#[from] SessionError),
}

impl Clone for Error {
    fn clone(&self) -> Self {
        match self {
            Self::ConnectRefused(c) => Self::ConnectRefused(*c),
            Self::Io(e) => Self::Io(std::io::Error::new(e.kind(), e.to_string())),
            Self::Decode(e) => Self::Decode(e.clone()),
            Self::Encode(e) => Self::Encode(e.clone()),
            Self::WindowFull => Self::WindowFull,
            Self::Timeout => Self::Timeout,
            Self::Disconnected => Self::Disconnected,
            Self::PingTimeout => Self::PingTimeout,
            Self::Session(e) => Self::Session(e.clone()),
        }
    }
}