Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How get an immutable Pin from a mutable Pin?

How to apply deref coercion from &mut to & for references that are wrapped inside Pin<>? That is, how to borrow Pin<&mut _> as Pin<&_>?

use std::pin::{Pin, pin};

fn take_immutable(_: Pin<&u32>) {}

let mutable_ref = pin!(0u32);
    
// Error: expected struct `Pin<&_>` 
//           found struct `Pin<&mut _>`
take_immutable(mutable_ref);

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Pin::as_ref() is your friend:

take_immutable(mutable_ref.as_ref());
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading