7171//! assert!(res);
7272//! }
7373//! ```
74- //!
75- //! # Cargo Features
76- //!
77- //! - `nightly` enables the use of unstable features. Turns [`AtomicRef::new`]
78- //! into `const fn`, making it callable in constant contexts.
79- //!
8074#![ no_std]
81- #! [ cfg_attr ( feature = "nightly" , feature ( const_if_match ) ) ]
75+
8276
8377use core:: sync:: atomic:: { AtomicPtr , Ordering } ;
8478use core:: marker:: PhantomData ;
@@ -183,29 +177,12 @@ macro_rules! static_atomic_ref {
183177 ( ) => ( ) ;
184178}
185179
186- macro_rules! const_fn_if_nightly {
187- (
188- $( #[ $meta: meta] ) *
189- $vis: vis fn $( $rest: tt) *
190- ) => {
191- $( #[ $meta] ) *
192- #[ cfg( feature = "nightly" ) ]
193- $vis const fn $( $rest) *
194-
195- $( #[ $meta] ) *
196- #[ cfg( not( feature = "nightly" ) ) ]
197- $vis fn $( $rest) *
198- } ;
199- }
200-
201- const_fn_if_nightly ! {
202- /// An internal helper function for converting `Option<&'a T>` values to
203- /// `*mut T` for storing in the `AtomicUsize`.
204- fn from_opt<' a, T >( p: Option <& ' a T >) -> * mut T {
205- match p {
206- Some ( p) => p as * const T as * mut T ,
207- None => null_mut( ) ,
208- }
180+ /// An internal helper function for converting `Option<&'a T>` values to
181+ /// `*mut T` for storing in the `AtomicUsize`.
182+ const fn from_opt < ' a , T > ( p : Option < & ' a T > ) -> * mut T {
183+ match p {
184+ Some ( p) => p as * const T as * mut T ,
185+ None => null_mut ( ) ,
209186 }
210187}
211188
@@ -216,22 +193,20 @@ unsafe fn to_opt<'a, T>(p: *mut T) -> Option<&'a T> {
216193}
217194
218195impl < ' a , T > AtomicRef < ' a , T > {
219- const_fn_if_nightly ! {
220- /// Creates a new `AtomicRef`.
221- ///
222- /// # Examples
223- ///
224- /// ```
225- /// use atomic_ref::AtomicRef;
226- ///
227- /// static VALUE: i32 = 10;
228- /// let atomic_ref = AtomicRef::new(Some(&VALUE));
229- /// ```
230- pub fn new( p: Option <& ' a T >) -> AtomicRef <' a, T > {
231- AtomicRef {
232- data: AtomicPtr :: new( from_opt( p) ) ,
233- _marker: PhantomData ,
234- }
196+ /// Creates a new `AtomicRef`.
197+ ///
198+ /// # Examples
199+ ///
200+ /// ```
201+ /// use atomic_ref::AtomicRef;
202+ ///
203+ /// static VALUE: i32 = 10;
204+ /// let atomic_ref = AtomicRef::new(Some(&VALUE));
205+ /// ```
206+ pub const fn new ( p : Option < & ' a T > ) -> AtomicRef < ' a , T > {
207+ AtomicRef {
208+ data : AtomicPtr :: new ( from_opt ( p) ) ,
209+ _marker : PhantomData ,
235210 }
236211 }
237212
0 commit comments