Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created September 20, 2019 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/528ce122067ee3ddfdf52acb1f5c6ff5 to your computer and use it in GitHub Desktop.
Save rust-play/528ce122067ee3ddfdf52acb1f5c6ff5 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#![feature(dropck_eyepatch)]
use std::{fmt, rc::Rc};
struct PeekOnDrop<T: fmt::Debug>(T);
unsafe impl<#[may_dangle] T: fmt::Debug> Drop for PeekOnDrop<T> {
fn drop(&mut self) {
println!("{:?}", self.0);
}
}
struct SelfRef<'a> {
value: Box<u8>,
rc: Option<Rc<PeekOnDrop<&'a u8>>>,
}
fn main() {
let mut sr = SelfRef {
rc: None,
value: Box::new(1),
};
sr.rc = Some(Rc::new(PeekOnDrop(&*sr.value)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment