File tree Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change 1
- //! Traits for abstracting over `std` atomics. Basically implementation detail!
1
+ //! Traits for abstracting over `std` atomics. Mostly hidden implementation detail.
2
2
//!
3
- //! This module only promises stability about the trait names and which types
4
- //! these traits are implemented by (though, new impls can be added at any
5
- //! time, of course). In particular, the traits' methods and other items are
6
- //! not part of the public API of `atomig`. Those items are also hidden in the
7
- //! documentation. And the traits are sealed anyway, so you can't implement
8
- //! them for your own types.
3
+ //! Most items of these traits are hidden and not part of the public API of this library.
4
+ //! You cannot implement these traits yourself.
9
5
10
6
use core:: { num:: Wrapping , sync:: atomic:: { self , Ordering } } ;
11
7
use super :: { Atom , AtomLogic , AtomInteger } ;
@@ -28,7 +24,6 @@ mod sealed {
28
24
/// the public API -- see the module docs.
29
25
pub trait PrimitiveAtom : Sized + Copy + sealed:: Sealed {
30
26
/// The standard library type that is the atomic version of `Self`.
31
- #[ doc( hidden) ]
32
27
type Impl ;
33
28
34
29
#[ doc( hidden) ]
Original file line number Diff line number Diff line change @@ -341,6 +341,26 @@ impl<T: Atom> Atomic<T> {
341
341
Self ( T :: Repr :: into_impl ( v. pack ( ) ) )
342
342
}
343
343
344
+ /// Creates a new atomic value from the underlying `Atomic*` type from `std`.
345
+ ///
346
+ /// Since [`Atom`] is a `trait` and `const fn`s in `trait`s are not supported yet,
347
+ /// the only way for this to be a `const fn` is
348
+ /// to take the underyling atomic impl type directly.
349
+ ///
350
+ /// This allows `static` `Atomic`s to be created.
351
+ ///
352
+ /// # Examples
353
+ ///
354
+ /// ```
355
+ /// use atomig::Atomic;
356
+ /// use std::sync::atomic::AtomicU32;
357
+ ///
358
+ /// static X: Atomic<u32> = Atomic::from_impl(AtomicU32::new(7));
359
+ /// ```
360
+ pub const fn from_impl ( v : <<T as Atom >:: Repr as PrimitiveAtom >:: Impl ) -> Self {
361
+ Self ( v)
362
+ }
363
+
344
364
/// Consumes the atomic and returns the contained value.
345
365
///
346
366
/// This is safe because passing `self` by value guarantees that no other
You can’t perform that action at this time.
0 commit comments