Git Product home page Git Product logo

Comments (4)

Nemo157 avatar Nemo157 commented on May 27, 2024

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 impl block (impl Foo::Projection<'_> { ... }) or the constructor type in a destructuring statement (let Foo::Projection { bar } = ...;) anyway, so neither of those methods would work even if declaring the associated type worked.

from pin-project.

Nemo157 avatar Nemo157 commented on May 27, 2024

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.

from pin-project.

taiki-e avatar taiki-e commented on May 27, 2024

I am thinking about two ways.
The first is to use an attribute too impl Foo and convert Foo to __FooProjection.

#[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 #[project] attribute currently does for let and match.

Another way is to allow naming the projected-type via the #[pin_project] attribute's argument.

#[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.

from pin-project.

Nemo157 avatar Nemo157 commented on May 27, 2024

Oh yeah, I forgot about the #[project] attribute, I've been meaning to take a look at what it actually does. So that already covers the latter usecase, and it would make sense to do something similar for both.

from pin-project.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.