memcached-async 0.0.1

Asynchronous memcached protocol parser
Documentation
use bytes::Bytes;

/// Framework error result.
pub type Result<T> = std::io::Result<T>;

/// Error category for protocol mapping.
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum ErrorKind {
    Client,
    Server,
    UnknownCommand,
}

/// Protocol-agnostic error type returned by handlers.
#[derive(Debug, Clone)]
pub struct Error {
    pub kind: ErrorKind,
    pub message: Bytes,
    pub close: bool,
}

impl Error {
    pub fn client<T: Into<Bytes>>(msg: T) -> Self {
        Self {
            kind: ErrorKind::Client,
            message: msg.into(),
            close: false,
        }
    }

    pub fn server<T: Into<Bytes>>(msg: T) -> Self {
        Self {
            kind: ErrorKind::Server,
            message: msg.into(),
            close: true,
        }
    }

    pub fn unknown<T: Into<Bytes>>(msg: T) -> Self {
        Self {
            kind: ErrorKind::UnknownCommand,
            message: msg.into(),
            close: false,
        }
    }

    pub fn with_close<T: Into<Bytes>>(kind: ErrorKind, msg: T, close: bool) -> Self {
        Self {
            kind,
            message: msg.into(),
            close,
        }
    }
}