-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Provide way to refer to projected type #43
Comments
I briefly experimented with a couple of ideas, the first was an inherent associated type: impl Foo {
type Projection = __FooProjection;
} that's currently unsupported (rust-lang/rust#8995) and would presumably require GATs. The other idea was to add a trait that had an associated type, which would need GATs as well. My experiments with GAT workarounds seem to indicate that you can't use associated types as the base type in an |
Another horrible idea I had was mod Foo {
pub(super) type Projection<'a> = super::__FooProjection<'a>;
} luckily modules and structs inhabit the same namespace so this is not possible. |
I am thinking about two ways. #[pin_project::project_impl]
impl Foo {
fn debug(&self) {}
}
// convert to..
impl<'__pin> __FooProjection<'__pin> {
fn debug(&self) {}
} This way is almost the same as what the Another way is to allow naming the projected-type via the #[pin_project::pin_project(projection = Bar)]
struct Foo {
#[pin]
bar: &'static str,
}
impl Bar<'_> {
fn debug(&self) {}
} We need to document that new lifetimes will be added, but this may be the best solution for this issue and rust-lang/pin-utils#21 at this time. |
Oh yeah, I forgot about the |
202: Allow naming the projected types r=taiki-e a=taiki-e By passing an argument with the same name as the method to the attribute, you can name the projection type returned from the method: ```rust #[pin_project( Replace, project = StructProj, project_ref = StructProjRef, project_replace = StructProjOwn, )] struct Struct<T> { #[pin] field: T, } let mut x = Struct { field: 0 }; let StructProj { field } = Pin::new(&mut x).project(); let StructProjRef { field } = Pin::new(&x).project_ref(); let StructProjOwn { field } = Pin::new(&mut x).project_replace(Struct { field: 1 }); ``` cc #43 Closes #124 TODO: * [x] add tests * [x] write docs * [x] separate unrelated changes; done in #214 * [x] msrv (`unrestricted_attribute_tokens` requires 1.34); done in #219 Co-authored-by: Taiki Endo <[email protected]>
A couple of things I've wanted to do is to be able to destructure the projection to avoid using
this.
all the time in methods, and implement helper methods directly on the projection. As an example this currently works because of a lack of hygiene:but it would be nice to have a way to do this that doesn't rely on the internal details of the macro.
The text was updated successfully, but these errors were encountered: