Skip to content

Commit cb4e7c5

Browse files
committed
Get rid of dependency on std
1 parent 5ac7a90 commit cb4e7c5

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/lib.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@
7171
//! assert!(res);
7272
//! }
7373
//! ```
74+
#![no_std]
7475

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;
7980

8081
/// A mutable Option<&'a, T> type which can be safely shared between threads.
8182
#[repr(C)]
@@ -104,6 +105,11 @@ pub const ATOMIC_U8_REF_INIT: AtomicRef<'static, u8> = AtomicRef {
104105
_marker: PhantomData,
105106
};
106107

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+
107113
/// A macro to define a statically allocated `AtomicRef<'static, T>` which is
108114
/// initialized to `None`.
109115
///
@@ -134,12 +140,12 @@ macro_rules! static_atomic_ref {
134140
};
135141
(@$VIS:ident, $(#[$attr:meta])* static $N:ident : $T:ty; $($t:tt)*) => {
136142
static_atomic_ref!(@MAKE TY, $VIS, $(#[$attr])*, $N);
137-
impl ::std::ops::Deref for $N {
143+
impl $crate::core_ops::Deref for $N {
138144
type Target = $crate::AtomicRef<'static, $T>;
139145
#[allow(unsafe_code)]
140146
fn deref<'a>(&'a self) -> &'a $crate::AtomicRef<'static, $T> {
141147
static STORAGE: $crate::AtomicRef<'static, u8> = $crate::ATOMIC_U8_REF_INIT;
142-
unsafe { ::std::mem::transmute(&STORAGE) }
148+
unsafe { $crate::core_mem::transmute(&STORAGE) }
143149
}
144150
}
145151
static_atomic_ref!($($t)*);
@@ -403,7 +409,7 @@ impl<'a, T> Default for AtomicRef<'a, T> {
403409

404410
#[cfg(test)]
405411
mod tests {
406-
use std::sync::atomic::Ordering;
412+
use core::sync::atomic::Ordering;
407413

408414
static_atomic_ref! {
409415
static FOO: AtomicRef<i32>;

0 commit comments

Comments
 (0)