Skip to content

Commit

Permalink
Add badges to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
timvermeulen committed Feb 25, 2020
1 parent 1950f5e commit 063ee84
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -110,19 +110,19 @@ impl<T, const N: usize> ConstBuffer<T, N> {
/// Creates a new `ConstBuffer` from a `MaybeUninit<[T; N]>`.
#[inline]
const fn from_maybe_uninit_array(maybe_uninit: MaybeUninit<[T; N]>) -> Self {
union Transmute<T, const N: usize> {
maybe_uninit: MaybeUninit<[T; N]>,
array: ManuallyDrop<[MaybeUninit<T>; N]>,
}

// SAFETY: `MaybeUninit<T>` 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<T>, 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<T, const N: usize> {
maybe_uninit: MaybeUninit<[T; N]>,
array: [MaybeUninit<T>; 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.
Expand Down

0 comments on commit 063ee84

Please sign in to comment.