Skip to content

Commit 27c0b65

Browse files
Added an example of usage where an unsafe block is not required
1 parent 598fcec commit 27c0b65

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

library/core/src/sync/atomic.rs

+12
Original file line numberDiff line numberDiff line change
@@ -3423,6 +3423,18 @@ macro_rules! atomic_int {
34233423
/// }
34243424
/// # }
34253425
/// ```
3426+
///
3427+
/// ```
3428+
#[doc = concat!($extra_feature, "use std::sync::atomic::", stringify!($atomic_type), ";")]
3429+
///
3430+
///
3431+
#[doc = concat!("let atomic_ref_1 = ", stringify!($atomic_type), "::new(1);")]
3432+
#[doc = concat!("let atomic_ref_2 = ", stringify!($atomic_type), "::new(2);")]
3433+
///
3434+
/// // Comparison of addresses is a safe operation and does not require an `unsafe` block.
3435+
/// let is_equal = atomic_ref_1.as_ptr() == atomic_ref_2.as_ptr();
3436+
/// assert!(is_equal || !is_equal);
3437+
/// ```
34263438
#[inline]
34273439
#[stable(feature = "atomic_as_ptr", since = "1.70.0")]
34283440
#[rustc_const_stable(feature = "atomic_as_ptr", since = "1.70.0")]

0 commit comments

Comments
 (0)