ruvio-client 0.2.5

RESP2 client for the Ruvio key-value server
Documentation
use std::fmt;

/// A transport failure, a broken RESP frame, or a Ruvio error reply.
#[derive(Debug)]
pub enum Error {
    /// The TCP connection failed or closed.
    Io(std::io::Error),
    /// The bytes on the socket were not a complete RESP2 value.
    Protocol(String),
    /// Ruvio returned a RESP error. The connection can still run the next command.
    Server(String),
}

impl fmt::Display for Error {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::Io(error) => write!(formatter, "{error}"),
            Error::Protocol(message) | Error::Server(message) => write!(formatter, "{message}"),
        }
    }
}

impl std::error::Error for Error {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Error::Io(error) => Some(error),
            Error::Protocol(_) | Error::Server(_) => None,
        }
    }
}

impl From<std::io::Error> for Error {
    fn from(error: std::io::Error) -> Self {
        Error::Io(error)
    }
}