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

Consider allowing naming the projected type #124

Closed
taiki-e opened this issue Oct 12, 2019 · 4 comments · Fixed by #202
Closed

Consider allowing naming the projected type #124

taiki-e opened this issue Oct 12, 2019 · 4 comments · Fixed by #202
Assignees
Labels
A-pin-projection Area: #[pin_project] C-enhancement Category: A new feature or an improvement for an existing one

Comments

@taiki-e
Copy link
Owner

taiki-e commented Oct 12, 2019

Currently, all ways for referring the projected type are provided by the #[project] attribute.

Ideally, I would like to write using inherent associated types (rust-lang/rust#8995) or generic associated types (rust-lang/rust#44265) as follows, but neither has been implemented yet:

impl Foo {
    type Projection<'pin> = __FooProjection<'pin>;
}

As implementing these features will take time (it seems that at least Chalk integration is necessary), we may allow naming as an alternative at this time.

I think there are two ways to provide these:

Related: #43

@taiki-e taiki-e added C-enhancement Category: A new feature or an improvement for an existing one A-pin-projection Area: #[pin_project] needs-discussion labels Oct 12, 2019
@taiki-e
Copy link
Owner Author

taiki-e commented Oct 12, 2019

At this time I don't have a strong opinion about whether this should be added, but I am a bit concerned that this can complicate the API.

@taiki-e
Copy link
Owner Author

taiki-e commented Apr 24, 2020

Given that #[project] isn't really available everywhere, I've come to feel that this makes sense.

Maybe something like this:

#[pin_project(project = FooProj, project_ref = FooProjRef)]
struct Foo<T> {
    #[pin]
    x T: ,
}

impl<T> Foo<'_, T> {}

(It should be mentioned in the documentation that a lifetime is added to the first position in generics.)

@taiki-e taiki-e self-assigned this Apr 24, 2020
bors bot added a commit that referenced this issue May 7, 2020
211: Hide generated items from --document-private-items r=taiki-e a=taiki-e

All of the generated items are private items, but it can be displayed in the document by using the `--document-private-items` flag.

Naming will be allowed by #202, so it would probably be preferable to only display it in the document if the user did a naming.

cc #124 #202
Related: #192

Co-authored-by: Taiki Endo <[email protected]>
@taiki-e
Copy link
Owner Author

taiki-e commented May 8, 2020

One of the cases that current #[project] cannot support is the following code.

#[pin_project::pin_project(Replace)]
enum E<T, U> {
    A(#[pin] T),
    B(U),
    C,
}

fn foo<T, U>(e: Pin<&mut E<T, Y>>) {
    if let E::A(_a) = e.project() { // needs #[project]
        // ..
    } else if E::B(_b) = e.project_replace(E::C) { // needs #[project_replace]
        //
    }
}

@taiki-e
Copy link
Owner Author

taiki-e commented May 31, 2020

It should be mentioned in the documentation that a lifetime is added to the first position in generics.

Oh, it seems I forgot to do this in #202.

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

Successfully merging a pull request may close this issue.

1 participant