From ecb881775d9d1c692e35e177f0053f79c6cc3f9f Mon Sep 17 00:00:00 2001 From: Lance Roy Date: Sun, 20 Dec 2020 15:02:19 -0800 Subject: [PATCH] Make library usable in no_std environments. Tests still require the standard library, but the library itself only needs the core library. --- src/lib.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cd2f6c1..5662581 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -182,10 +182,12 @@ //! [`Unpinned`]: struct.Unpinned.html //! [`!Unpin`]: https://doc.rust-lang.org/std/pin/index.html#unpin -use std::marker::PhantomData; -use std::ops::Deref; -use std::ops::DerefMut; -use std::pin::Pin; +#![cfg_attr(not(test), no_std)] + +use core::marker::PhantomData; +use core::ops::Deref; +use core::ops::DerefMut; +use core::pin::Pin; /// Struct that represents data that is pinned to the stack, at the point of declaration. /// @@ -335,7 +337,7 @@ where /// [`PinStack`]: type.PinStack.html pub struct Unpinned> { u: U, - t: std::marker::PhantomData, + t: core::marker::PhantomData, } unsafe impl> FromUnpinned> for T { @@ -364,7 +366,7 @@ macro_rules! internal_pin_stack { let $id: $crate::PinStack<_> = unsafe { let $id = $crate::StackPinned::new(&mut $id); - std::pin::Pin::new_unchecked($id) + core::pin::Pin::new_unchecked($id) }; }; (mut $id:ident) => { @@ -372,7 +374,7 @@ macro_rules! internal_pin_stack { let mut $id: $crate::PinStack<_> = unsafe { let $id = $crate::StackPinned::new(&mut $id); - std::pin::Pin::new_unchecked($id) + core::pin::Pin::new_unchecked($id) }; }; } @@ -383,7 +385,7 @@ where Dest: FromUnpinned, { let (dest, data) = FromUnpinned::::from_unpinned(source); - std::ptr::write(pdest, dest); + core::ptr::write(pdest, dest); FromUnpinned::::on_pin(&mut *pdest, data); } @@ -468,8 +470,8 @@ mod tests { use super::FromUnpinned; use super::PinStack; use super::Unpinned; - use std::marker::PhantomPinned; - use std::ptr::NonNull; + use core::marker::PhantomPinned; + use core::ptr::NonNull; struct Unmovable { data: String,