Merge branch '0.4' into master

* 0.4:
  0.4.11
  TEST: Update tests for new MaybeUninit usage
  FEAT: Use stable MaybeUninit when we can (feature detected)
This commit is contained in:
bluss
2019-07-10 17:51:59 +02:00
7 changed files with 74 additions and 13 deletions
+5 -2
View File
@@ -50,9 +50,12 @@ use std::fmt;
use std::io;
#[cfg(has_manually_drop_in_union)]
#[cfg(has_stable_maybe_uninit)]
#[path="maybe_uninit_stable.rs"]
mod maybe_uninit;
#[cfg(not(has_manually_drop_in_union))]
#[cfg(all(not(has_stable_maybe_uninit), has_manually_drop_in_union))]
mod maybe_uninit;
#[cfg(all(not(has_stable_maybe_uninit), not(has_manually_drop_in_union)))]
#[path="maybe_uninit_nodrop.rs"]
mod maybe_uninit;
+40
View File
@@ -0,0 +1,40 @@
use array::Array;
use std::mem::MaybeUninit as StdMaybeUninit;
pub struct MaybeUninit<T> {
inner: StdMaybeUninit<T>,
}
impl<T> MaybeUninit<T> {
/// Create a new MaybeUninit with uninitialized interior
pub unsafe fn uninitialized() -> Self {
MaybeUninit { inner: StdMaybeUninit::uninit() }
}
/// Create a new MaybeUninit from the value `v`.
pub fn from(v: T) -> Self {
MaybeUninit { inner: StdMaybeUninit::new(v) }
}
// Raw pointer casts written so that we don't reference or access the
// uninitialized interior value
/// Return a raw pointer to the start of the interior array
pub fn ptr(&self) -> *const T::Item
where T: Array
{
// std MaybeUninit creates a &self.value reference here which is
// not guaranteed to be sound in our case - we will partially
// initialize the value, not always wholly.
self.inner.as_ptr() as *const T::Item
}
/// Return a mut raw pointer to the start of the interior array
pub fn ptr_mut(&mut self) -> *mut T::Item
where T: Array
{
self.inner.as_mut_ptr() as *mut T::Item
}
}