Updating old code using old unsafe `Generator` to new `Pin` style `Generator`

In some toy code I have to solve project euler exercises, I write some Generator that could be used as Iterator to lazyly create a sequence of prime numbers.

Its implementation is probably not perfect, as well as the rest of the code :wink:

This code used to work when I wrote it ~9 months ago. But it doesn with the current nightly.

I'm unable to update this code by myself, probably caused by not really understanding Pin :slight_smile:

The version that currently does not work is available at GitLab.

Can someone help me converting that code to a version that works with current nightlies?

I tried by randomly wrapping into Pin, but that didn't work and the error message basically was the same (or variations thereof):

error[E0599]: no method named `resume` found for type `std::pin::Pin<std::boxed::Box<(dyn std::ops::Generator<Return = (), Yield = u64> + std::marker::Unpin + 'static)>>` in the current scope

While from looking at the Generator docs it looks like it should be implementedโ€ฆ

You need to use .as_mut() to explicitely (re)borrow the pinned value (with Pin this is no longer implicit)

2 Likes

Thank you, that seems to have helped :wink:

After this commit it works again!

1 Like