|
71 | 71 | //! assert!(res);
|
72 | 72 | //! }
|
73 | 73 | //! ```
|
| 74 | +#![no_std] |
74 | 75 |
|
75 |
| -use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; |
76 |
| -use std::marker::PhantomData; |
77 |
| -use std::fmt; |
78 |
| -use std::default::Default; |
| 76 | +use core::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; |
| 77 | +use core::marker::PhantomData; |
| 78 | +use core::fmt; |
| 79 | +use core::default::Default; |
79 | 80 |
|
80 | 81 | /// A mutable Option<&'a, T> type which can be safely shared between threads.
|
81 | 82 | #[repr(C)]
|
@@ -104,6 +105,11 @@ pub const ATOMIC_U8_REF_INIT: AtomicRef<'static, u8> = AtomicRef {
|
104 | 105 | _marker: PhantomData,
|
105 | 106 | };
|
106 | 107 |
|
| 108 | +/// Re-export `core` for `static_atomic_ref!` (which may be used in a |
| 109 | +/// non-`no_std` crate, where `core` is unavailable). |
| 110 | +#[doc(hidden)] |
| 111 | +pub use core::{mem as core_mem, ops as core_ops}; |
| 112 | + |
107 | 113 | /// A macro to define a statically allocated `AtomicRef<'static, T>` which is
|
108 | 114 | /// initialized to `None`.
|
109 | 115 | ///
|
@@ -134,12 +140,12 @@ macro_rules! static_atomic_ref {
|
134 | 140 | };
|
135 | 141 | (@$VIS:ident, $(#[$attr:meta])* static $N:ident : $T:ty; $($t:tt)*) => {
|
136 | 142 | static_atomic_ref!(@MAKE TY, $VIS, $(#[$attr])*, $N);
|
137 |
| - impl ::std::ops::Deref for $N { |
| 143 | + impl $crate::core_ops::Deref for $N { |
138 | 144 | type Target = $crate::AtomicRef<'static, $T>;
|
139 | 145 | #[allow(unsafe_code)]
|
140 | 146 | fn deref<'a>(&'a self) -> &'a $crate::AtomicRef<'static, $T> {
|
141 | 147 | static STORAGE: $crate::AtomicRef<'static, u8> = $crate::ATOMIC_U8_REF_INIT;
|
142 |
| - unsafe { ::std::mem::transmute(&STORAGE) } |
| 148 | + unsafe { $crate::core_mem::transmute(&STORAGE) } |
143 | 149 | }
|
144 | 150 | }
|
145 | 151 | static_atomic_ref!($($t)*);
|
@@ -403,7 +409,7 @@ impl<'a, T> Default for AtomicRef<'a, T> {
|
403 | 409 |
|
404 | 410 | #[cfg(test)]
|
405 | 411 | mod tests {
|
406 |
| - use std::sync::atomic::Ordering; |
| 412 | + use core::sync::atomic::Ordering; |
407 | 413 |
|
408 | 414 | static_atomic_ref! {
|
409 | 415 | static FOO: AtomicRef<i32>;
|
|
0 commit comments