From 063ee8464b17cb96f15e693e6f545792a2063c32 Mon Sep 17 00:00:00 2001 From: Tim Vermeulen Date: Tue, 4 Feb 2020 00:58:51 +0100 Subject: [PATCH] Add badges to readme --- src/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3b20aea..d01071e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,7 +83,7 @@ extern crate std; use core::{ cmp, fmt::{self, Debug, Formatter}, - mem::MaybeUninit, + mem::{ManuallyDrop, MaybeUninit}, ops::{Bound, Range, RangeBounds}, ptr, slice::{self, SliceIndex}, @@ -110,19 +110,19 @@ impl ConstBuffer { /// Creates a new `ConstBuffer` from a `MaybeUninit<[T; N]>`. #[inline] const fn from_maybe_uninit_array(maybe_uninit: MaybeUninit<[T; N]>) -> Self { + union Transmute { + maybe_uninit: MaybeUninit<[T; N]>, + array: ManuallyDrop<[MaybeUninit; N]>, + } + // SAFETY: `MaybeUninit` is guaranteed to have the same layout as `T`, and // arrays are guaranteed to lay out their elements consecutively, so // `MaybeUninit<[T; N]>` and `[MaybeUninit, N]` are guaranteed to have the // same layout. See: // - https://doc.rust-lang.org/beta/std/mem/union.MaybeUninit.html#layout // - https://doc.rust-lang.org/reference/type-layout.html#array-layout - unsafe { - union Transmute { - maybe_uninit: MaybeUninit<[T; N]>, - array: [MaybeUninit; N], - } - Self(Transmute { maybe_uninit }.array) - } + let array = unsafe { Transmute { maybe_uninit }.array }; + Self(ManuallyDrop::into_inner(array)) } /// Creates a new `ConstBuffer` from an array with the same size.