use void::Void;
use void;
use ::core::fmt;
#[derive(Debug)]
pub enum IOError<R, W> {
Read(R),
Write(W),
}
impl<R, W> IOError<R, W> {
pub fn merge<E>(e: IOError<R, W>) -> E where R: Into<E>, W: Into<E> {
match e {
IOError::Read(e) => e.into(),
IOError::Write(e) => e.into(),
}
}
pub fn as_ref(&self) -> IOError<&R, &W> {
match *self {
IOError::Read(ref f) => IOError::Read(f),
IOError::Write(ref s) => IOError::Write(s),
}
}
pub fn as_ref_mut(&mut self) -> IOError<&mut R, &mut W> {
match *self {
IOError::Read(ref mut f) => IOError::Read(f),
IOError::Write(ref mut s) => IOError::Write(s),
}
}
}
#[derive(Debug)]
pub enum ReadExactError<E> {
Other(E),
UnexpectedEnd,
}
impl<E> From<E> for ReadExactError<E> {
fn from(e: E) -> Self {
ReadExactError::Other(e)
}
}
#[derive(Debug)]
pub enum ChainError<F, S> {
First(F),
Second(S),
}
impl<F, S> ChainError<F, S> {
pub fn merge<E>(self) -> E where F: Into<E>, S: Into<E> {
match self {
ChainError::First(f) => f.into(),
ChainError::Second(s) => s.into(),
}
}
pub fn as_ref(&self) -> ChainError<&F, &S> {
match *self {
ChainError::First(ref f) => ChainError::First(f),
ChainError::Second(ref s) => ChainError::Second(s),
}
}
pub fn as_ref_mut(&mut self) -> ChainError<&mut F, &mut S> {
match *self {
ChainError::First(ref mut f) => ChainError::First(f),
ChainError::Second(ref mut s) => ChainError::Second(s),
}
}
}
#[derive(Debug)]
pub enum IntrError<E> {
Other(E),
Interrupted,
}
pub trait IntoIntrError {
type NonIntr;
fn into_intr_error(self) -> IntrError<Self::NonIntr>;
}
impl<E> IntoIntrError for IntrError<E> {
type NonIntr = E;
fn into_intr_error(self) -> IntrError<Self::NonIntr> {
self
}
}
impl<T> From<Void> for IntrError<T> {
fn from(e: Void) -> Self {
void::unreachable(e)
}
}
#[derive(Debug)]
pub enum BufError<B, E> {
End,
BufferErr(B),
OtherErr(E),
}
#[derive(Debug)]
pub enum ExtendError<R, E> {
ReadErr(R),
ExtendErr(E),
}
#[derive(Debug)]
pub struct BufferOverflow;
impl fmt::Display for BufferOverflow {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "provided buffer was too small")
}
}