pub struct ParserResult<'a, T, E> {
pub source: &'a str,
pub typ: ParserResultType<T, E>,
}
pub enum ParserResultType<T, E> {
Ok(T),
Err(E),
Incomplete,
}
impl<'a, T, E> Try for ParserResult<'a, T, E> {
type Output = (&'a str, T);
type Residual = ParserResult<'a, Infallible, E>;
fn from_output(output: Self::Output) -> Self {
Self::from_val(output.0, output.1)
}
fn branch(self) -> std::ops::ControlFlow<Self::Residual, Self::Output> {
match self.typ {
ParserResultType::Ok(v) => ControlFlow::Continue((self.source, v)),
ParserResultType::Err(e) => ControlFlow::Break(ParserResult::from_err(self.source, e)),
ParserResultType::Incomplete => {
ControlFlow::Break(ParserResult::incomplete(self.source))
}
}
}
}
impl<'a, T, E, F: From<E>> FromResidual<ParserResult<'a, Infallible, F>>
for ParserResult<'a, T, F>
{
fn from_residual(residual: <Self as Try>::Residual) -> Self {
Self {
source: residual.source,
typ: match residual.typ {
ParserResultType::Ok(v) => ParserResultType::Ok(v),
ParserResultType::Err(e) => ParserResultType::Err(e.into()),
ParserResultType::Incomplete => ParserResultType::Incomplete,
},
}
}
}
I'm trying to implement the try trait (using the unstable feature try_trait_v2) for my ParserResult type, but I'm getting this error: