use bytes::Bytes;
pub type Result<T> = std::io::Result<T>;
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum ErrorKind {
Client,
Server,
UnknownCommand,
}
#[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,
}
}
}