Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pin-projecting in-line tuples #349

Open
yoshuawuyts opened this issue Nov 17, 2022 · 2 comments
Open

Pin-projecting in-line tuples #349

yoshuawuyts opened this issue Nov 17, 2022 · 2 comments
Labels
C-enhancement Category: A new feature or an improvement for an existing one

Comments

@yoshuawuyts
Copy link

The following currently works:

use pin_project::pin_project;
use core::future::Future;

#[pin_project]
struct Pinned<A: Future, B: Future>(#[pin] A, #[pin] B);

But this doesn't:

use pin_project::pin_project;
use core::future::Future;

#[pin_project]
struct Pinned<A: Future, B: Future> {
    futures: (#[pin] A, #[pin] B),
}

So instead we now have to do:

use pin_project::pin_project;
use core::future::Future;

#[pin_project]
struct Futures<A: Future, B: Future> (#[pin] A, #[pin] B);

#[pin_project]
struct Pinned<A: Future, B: Future> {
    futures: Futures<A, B>,
}

We ran into some issues with this in yoshuawuyts/futures-concurrency#74. I'm not sure how feasible this would be to provide, but being able to pin-project into individual enum fields would save us from having to generate an intermediate struct. So I figured I'd raise it here; hope that's alright!

@taiki-e taiki-e added the C-enhancement Category: A new feature or an improvement for an existing one label Nov 18, 2022
@taiki-e
Copy link
Owner

taiki-e commented Nov 18, 2022

Thanks for the suggestion! At first glance, this seems reasonable to me.

@taiki-e
Copy link
Owner

taiki-e commented Nov 18, 2022

Another approach is providing a trait for pin projection and implementing it for tuples. This allows the removal of tuple-struct workaround. However, unfortunately, this approach cannot support arbitrarily sized tuples, though.
As mentioned in 1.0.0 tracking issue, this approach needs recently stabilized GAT. Something like the following:

trait PinProject {
    type Projection<'a>;
    fn project<'a>(self: Pin<&'a mut Self>) -> Self::Projection<'a>;
}

On the other hand, this probably has the advantage of being able to support slices and arrays. (Self::Projection will probably be the iterator instead of slice/array, though.)

(We can probably provide both.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: A new feature or an improvement for an existing one
Projects
None yet
Development

No branches or pull requests

2 participants