AndWass / pushgen

Apache License 2.0
27 stars 4 forks source link

Support for Boxed Generators #35

Closed epage closed 3 years ago

epage commented 3 years ago

I think the impl argument for run makes it so Generator is not object-safe and therefore can't be boxed

fn run(&mut self, output: impl FnMut(Self::Output) -> crate::ValueResult) -> GeneratorResult;

While in most cases, boxing isn't needed, for a trait to return a Generator, it needs to be boxed to allow the trait impls to create whatever Generator they need.

AndWass commented 3 years ago

Hmm tricky one!

I have an idea that involves adding another DynGenerator trait which is object safe with blanket implementation for Generator. Shouldn't you then be able to box a dyn DynGenerator? I'll do some testing!

AndWass commented 3 years ago

What do you think of the approach taken in #37?

epage commented 3 years ago

Looks good to me