I’d imagine the following:
use ::std::{
*,
ops::{
GeneratorState,
Try,
},
};
impl<Y, R> Try for GeneratorState<Y, R>
where
Y : Sized,
R : Try,
{
type Ok = GeneratorState<Y, R::Ok>;
type Error = R::Error;
/* etc, with:
Yielded(y) <=> Ok(Yielded(y)),
Complete(Ok(r)) <=> Ok(Complete(r)),
Complete(Err(r)) <=> Err(r),
*/
}
And then a fallible generator (with error E) would just impl Generator<Return = Result<(), E>, >)
Of course, that differs from current Iterator::next(_) -> Option<_> but I’d expect the following kind of trait to emerge:
pub trait TryIterator
{
type Item : Sized;
type Error : Sized /*+ ::std::error::Error ? */;
fn try_next (
self: &mut Self,
) -> GeneratorState< Item, Result<(), Error> >;
// or a new IteratorState that would mirror GeneratorState dichotomy
}
A last idea would be to flatten GeneratorState< Y, Result<T, E> > (3-branch enum) like Futures initially did, but since Futures “unflattened” afterwards (I guess the never type is still not mature enough), I don’t know if we want to go down the same path.