Created
September 20, 2019 21:38
-
-
Save rust-play/528ce122067ee3ddfdf52acb1f5c6ff5 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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