use std::error::Error as StdError;
use std::fmt;
use std::str::Utf8Error;
use std::string::FromUtf8Error;
use self::Error::{
Method,
Version,
Header,
Status,
TooLarge,
Utf8
};
pub type Result<T> = ::std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
Method,
Version,
Header,
TooLarge,
Status,
Utf8(Utf8Error),
#[doc(hidden)]
__Nonexhaustive(Void)
}
#[doc(hidden)]
pub struct Void(());
impl fmt::Debug for Void {
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
unreachable!()
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Utf8(ref e) => fmt::Display::fmt(e, f),
ref e => f.write_str(e.static_description()),
}
}
}
impl Error {
fn static_description(&self) -> &str {
match *self {
Method => "invalid Method specified",
Version => "invalid HTTP version specified",
Header => "invalid Header provided",
TooLarge => "message head is too large",
Status => "invalid Status provided",
Utf8(_) => "invalid UTF-8 string",
Error::__Nonexhaustive(..) => unreachable!(),
}
}
}
impl StdError for Error {
fn description(&self) -> &str {
self.static_description()
}
fn cause(&self) -> Option<&dyn StdError> {
match *self {
Utf8(ref error) => Some(error),
Error::__Nonexhaustive(..) => unreachable!(),
_ => None,
}
}
}
impl From<Utf8Error> for Error {
fn from(err: Utf8Error) -> Error {
Utf8(err)
}
}
impl From<FromUtf8Error> for Error {
fn from(err: FromUtf8Error) -> Error {
Utf8(err.utf8_error())
}
}
#[doc(hidden)]
trait AssertSendSync: Send + Sync + 'static {}
#[doc(hidden)]
impl AssertSendSync for Error {}