the.bay.news

Scope pinning `&mut T`

The Rust Programming Language Forum
Scope pinning `&mut T`
Hi, I had an idea for a primitive like that that will allow safely pinning &mut T. What do you think about it? #![no_std] use core::mem::{forget, ManuallyDrop}; use core::pin::Pin; use core::ptr; pub fn scope_pin<T, R, F>(place: &mut T, replacement: T, f: F) -> R where F: FnOnce(Pin<&mut T>) -> R, { struct Restore<T> { ptr: *mut T, replacement: ManuallyDrop<T>, } struct Bomb; impl Drop for Bomb { fn drop(&mut self) { panic!("drop unwou...

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.