How to put a future in Pin<Box<>> without .boxed()?

I cannot use .boxed() because it triggers errors about "one type is more general than the other".
So I use Box::pin() instead which works fine. However, the reason I use box at all here is that I need to reduce the type size of the future because I hit the compiler limit, so I need to cast it to Box<Pin<dyn ..>> I suppose? Will that help?

But it seems I cannot escape my fate which is "one type is more general than the other": https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=c0b057e9f9f6b9be9e064c3d68f57676 (edit: wrong link)

I have been wrestling with these errors almost a whole week and I'm desperate for a solution. Please help :tired_face:

I must admit, the error message is utterly confusing. I think it's worth filing a bug about it.

Removing this line makes it compile:

.then(move |x| async move {x})

I know that removing that line solves the problem, and I forgot to say: this is a very reduced test case deriving from a larger application where I actually need the then call, but where I do something more, namely

        .then(move |x| async move {
            delay_for(Duration::from_secs(some_time)).await;
            x
        })

There is an issue already:

Some threads from the user forum:

It seems it's sometimes related to lifetimes of the closure. Sometimes you can work around that with a dedicated function on which you can set for<'a>, although nobody has posted an example of that I think.

In the last thread it seems to be related to Send.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.