|
6 | 6 | //!
|
7 | 7 | //! This module does not require `std` feature.
|
8 | 8 |
|
9 |
| -use core::{ |
10 |
| - num::NonZeroUsize, |
11 |
| - sync::atomic::{AtomicUsize, Ordering}, |
12 |
| -}; |
| 9 | +#[cfg(feature = "atomic-polyfill")] |
| 10 | +use atomic_polyfill as atomic; |
| 11 | +#[cfg(not(feature = "atomic-polyfill"))] |
| 12 | +use core::sync::atomic; |
| 13 | + |
| 14 | +use atomic::{AtomicUsize, Ordering}; |
| 15 | +use core::num::NonZeroUsize; |
13 | 16 |
|
14 | 17 | /// A thread-safe cell which can be written to only once.
|
15 | 18 | #[derive(Default, Debug)]
|
@@ -160,21 +163,23 @@ pub use self::once_box::OnceBox;
|
160 | 163 |
|
161 | 164 | #[cfg(feature = "alloc")]
|
162 | 165 | mod once_box {
|
163 |
| - use core::{ |
164 |
| - marker::PhantomData, |
165 |
| - ptr, |
166 |
| - sync::atomic::{AtomicPtr, Ordering}, |
167 |
| - }; |
| 166 | + use super::atomic::{AtomicPtr, Ordering}; |
| 167 | + use core::{marker::PhantomData, ptr}; |
168 | 168 |
|
169 | 169 | use alloc::boxed::Box;
|
170 | 170 |
|
171 | 171 | /// A thread-safe cell which can be written to only once.
|
172 |
| - #[derive(Debug)] |
173 | 172 | pub struct OnceBox<T> {
|
174 | 173 | inner: AtomicPtr<T>,
|
175 | 174 | ghost: PhantomData<Option<Box<T>>>,
|
176 | 175 | }
|
177 | 176 |
|
| 177 | + impl<T> core::fmt::Debug for OnceBox<T> { |
| 178 | + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 179 | + write!(f, "OnceBox({:?})", self.inner.load(Ordering::Relaxed)) |
| 180 | + } |
| 181 | + } |
| 182 | + |
178 | 183 | impl<T> Default for OnceBox<T> {
|
179 | 184 | fn default() -> Self {
|
180 | 185 | Self::new()
|
|
0 commit comments