Skip to content

Instantly share code, notes, and snippets.

@DonghyungKo
Created April 12, 2021 13:19
Show Gist options
  • Save DonghyungKo/889fec5ad910f21a6a2098deaddafbc4 to your computer and use it in GitHub Desktop.
Save DonghyungKo/889fec5ad910f21a6a2098deaddafbc4 to your computer and use it in GitHub Desktop.
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