Git Product home page Git Product logo

Comments (4)

taiki-e avatar taiki-e commented on June 24, 2024 1

I also commented on rust-lang/rust#72477, but this way should fix it completely:

playground

#[pin_project::pin_project]
pub struct A<'a, R> {
    buf: &'a mut [u8],

    #[pin]
    stuff: R,
}

impl<'a> Foo<'a> {
    fn foo(mut self: std::pin::Pin<&mut Self>) {
        let this = self.project();
        let (_, rest) = std::mem::replace(&mut *this.buf, &mut []).split_at_mut(1);
        *this.buf = rest;
    }
}

from pin-project.

taiki-e avatar taiki-e commented on June 24, 2024

Hmm... I could reproduce this without pin-project (playground):

pub struct Foo<'a> {
    buf: &'a mut [u8],
}

impl<'a> Foo<'a> {
    fn foo(self: std::pin::Pin<&mut Self>) {
        self.buf = &mut self.buf[1..];
    }
}

I guess this related to rust-lang/rust#54934, but I'll look into this more.

from pin-project.

taiki-e avatar taiki-e commented on June 24, 2024

Ok, this looks like rust-lang/rust#72337 and can be fixed by adding lifetime 'a to std::pin::Pin<&mut Self>:

playground

  impl<'a, R> Foo<'a, R> {
-     fn foo(self: std::pin::Pin<&mut Self>) {
+     fn foo(self: std::pin::Pin<&'a mut Self>) {
          let this = self.project();
          *this.buf = &mut this.buf[1..];
      }
  }

from pin-project.

Ekleog avatar Ekleog commented on June 24, 2024

Oh. You're right, this isn't related to pin-project at all, sorry for having bothered you with it!

This being said, your solution unfortunately requires the Pin to be borrowed for the lifetime of the whole struct, which isn't the API I'm looking for, but I'm going to raise that point with the compiler directly.

Thank you! :D

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.