aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2019-02-15 19:52:25 +0100
committerGravatar Jorge Aparicio <jorge@japaric.io> 2019-02-19 12:37:25 +0100
commit88078e7770a2beda072ac37f89e2a81e5a9cb243 (patch)
treeeea481dcf82623ebd9830fc04923f3b4ac127d41 /src
parentc91b14bcd49f05ea40617dbd3166afa63234cb91 (diff)
downloadrtic-88078e7770a2beda072ac37f89e2a81e5a9cb243.tar.gz
rtic-88078e7770a2beda072ac37f89e2a81e5a9cb243.tar.zst
rtic-88078e7770a2beda072ac37f89e2a81e5a9cb243.zip
add "nightly" feature
Diffstat (limited to 'src')
-rw-r--r--src/export.rs65
-rw-r--r--src/lib.rs1
2 files changed, 62 insertions, 4 deletions
diff --git a/src/export.rs b/src/export.rs
index 6eae65f2..f8fc8157 100644
--- a/src/export.rs
+++ b/src/export.rs
@@ -1,8 +1,10 @@
//! IMPLEMENTATION DETAILS. DO NOT USE ANYTHING IN THIS MODULE
-#[cfg(not(debug_assertions))]
+#[cfg(all(not(feature = "nightly"), not(debug_assertions)))]
use core::hint;
-use core::{cell::Cell, ptr, u8};
+#[cfg(not(feature = "nightly"))]
+use core::ptr;
+use core::{cell::Cell, u8};
#[cfg(armv7m)]
use cortex_m::register::basepri;
@@ -64,17 +66,72 @@ impl Priority {
}
}
-// TODO(MaybeUninit) Until core::mem::MaybeUninit is stabilized we use our own (inefficient)
-// implementation
+#[cfg(feature = "nightly")]
+pub struct MaybeUninit<T> {
+ // we newtype so the end-user doesn't need `#![feature(maybe_uninit)]` in their code
+ inner: core::mem::MaybeUninit<T>,
+}
+
+#[cfg(feature = "nightly")]
+impl<T> MaybeUninit<T> {
+ pub const fn uninitialized() -> Self {
+ MaybeUninit {
+ inner: core::mem::MaybeUninit::uninitialized(),
+ }
+ }
+
+ pub fn as_ptr(&self) -> *const T {
+ self.inner.as_ptr()
+ }
+
+ pub fn as_mut_ptr(&mut self) -> *mut T {
+ self.inner.as_mut_ptr()
+ }
+
+ pub fn set(&mut self, value: T) -> &mut T {
+ self.inner.set(value)
+ }
+}
+
+#[cfg(not(feature = "nightly"))]
pub struct MaybeUninit<T> {
value: Option<T>,
}
+#[cfg(not(feature = "nightly"))]
impl<T> MaybeUninit<T> {
pub const fn uninitialized() -> Self {
MaybeUninit { value: None }
}
+ pub fn as_ptr(&self) -> *const T {
+ if let Some(x) = self.value.as_ref() {
+ x
+ } else {
+ match () {
+ // Try to catch UB when compiling in release with debug assertions enabled
+ #[cfg(debug_assertions)]
+ () => unreachable!(),
+ #[cfg(not(debug_assertions))]
+ () => unsafe { hint::unreachable_unchecked() },
+ }
+ }
+ }
+
+ pub fn as_mut_ptr(&mut self) -> *mut T {
+ if let Some(x) = self.value.as_mut() {
+ x
+ } else {
+ match () {
+ // Try to catch UB when compiling in release with debug assertions enabled
+ #[cfg(debug_assertions)]
+ () => unreachable!(),
+ #[cfg(not(debug_assertions))]
+ () => unsafe { hint::unreachable_unchecked() },
+ }
+ }
+ }
+
pub unsafe fn get_ref(&self) -> &T {
if let Some(x) = self.value.as_ref() {
x
diff --git a/src/lib.rs b/src/lib.rs
index 9914aaf4..6c79f6c7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -36,6 +36,7 @@
//! [`Instant`]: struct.Instant.html
//! [`Duration`]: struct.Duration.html
+#![cfg_attr(feature = "nightly", feature(maybe_uninit))]
#![deny(missing_docs)]
#![deny(warnings)]
#![no_std]