Created
March 19, 2021 07:33
-
-
Save y21/d6cba7f2977d41946d0e623cc15c7754 to your computer and use it in GitHub Desktop.
ManualDrop
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
use std::ops::{Drop, Deref}; | |
#[derive(Debug)] | |
struct ManualDrop<T>(*mut T); | |
impl<T> ManualDrop<T> { | |
pub fn new(data: T) -> ManualDrop<T> { | |
Self(Box::into_raw(Box::new(data))) | |
} | |
} | |
impl<T> Deref for ManualDrop<T> { | |
type Target = T; | |
fn deref(&self) -> &Self::Target { | |
unsafe { &*self.0 } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment