use self::IResult::*;
pub type Err = u32;
#[derive(Debug,PartialEq,Eq)]
pub enum Needed {
Unknown,
Size(u32)
}
#[derive(Debug,PartialEq,Eq)]
pub enum IResult<I,O> {
Done(I,O),
Error(Err),
Incomplete(Needed)
}
impl<I,O> IResult<I,O> {
pub fn is_done(&self) -> bool {
match self {
&Done(_,_) => true,
_ => false
}
}
pub fn is_err(&self) -> bool {
match self {
&Error(_) => true,
_ => false
}
}
pub fn is_incomplete(&self) -> bool {
match self {
&Incomplete(_) => true,
_ => false
}
}
}
pub trait GetInput<I> {
fn remaining_input(&self) -> Option<I>;
}
pub trait GetOutput<O> {
fn output(&self) -> Option<O>;
}
impl<'a,I,O> GetInput<&'a[I]> for IResult<&'a[I],O> {
fn remaining_input(&self) -> Option<&'a[I]> {
match self {
&Done(ref i,_) => Some(*i),
_ => None
}
}
}
impl<'a,O> GetInput<()> for IResult<(),O> {
fn remaining_input(&self) -> Option<()> {
match self {
&Done((),_) => Some(()),
_ => None
}
}
}
impl<'a,I,O> GetOutput<&'a[O]> for IResult<I,&'a[O]> {
fn output(&self) -> Option<&'a[O]> {
match self {
&Done(_, ref o) => Some(*o),
_ => None
}
}
}
impl<'a,I> GetOutput<()> for IResult<I,()> {
fn output(&self) -> Option<()> {
match self {
&Done(_,()) => Some(()),
_ => None
}
}
}