Created
April 12, 2021 13:19
-
-
Save DonghyungKo/889fec5ad910f21a6a2098deaddafbc4 to your computer and use it in GitHub Desktop.
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
pub struct Unique<T: ?Sized> { | |
ptr: *const T, | |
_marker: PhantomData<T>, | |
} | |
impl<T: Sized> Unique<T> { | |
/// Creates a new `Unique` that is dangling, but well-aligned | |
/// This is useful for initializing types which lazily allocate, like `Vec` | |
fn empty() -> Self { | |
let ptr = std::mem::align_of::<T>() as *mut T; | |
Self { | |
ptr, | |
_marker: PhantomData, | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment