]> git.lizzy.rs Git - rust.git/commitdiff
impl Debug for Atomic types
authorarthurprs <arthurprs@gmail.com>
Sun, 19 Jul 2015 16:11:30 +0000 (13:11 -0300)
committerarthurprs <arthurprs@gmail.com>
Mon, 20 Jul 2015 17:11:38 +0000 (14:11 -0300)
src/libcore/atomic.rs

index a77df0966431383d92a3bac660a745ff82b2987b..c6434e71957ae261ea717463d592e2ead0ad8375 100644 (file)
@@ -78,6 +78,7 @@
 use cell::UnsafeCell;
 
 use default::Default;
+use fmt;
 
 /// A boolean type which can be safely shared between threads.
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -1089,3 +1090,23 @@ pub fn fence(order: Ordering) {
         }
     }
 }
+
+macro_rules! impl_Debug {
+    ($($t:ident)*) => ($(
+        #[stable(feature = "atomic_debug", since = "1.3.0")]
+        impl fmt::Debug for $t {
+            fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+                f.debug_tuple(stringify!($t)).field(&self.load(Ordering::SeqCst)).finish()
+            }
+        }
+    )*);
+}
+
+impl_Debug!{ AtomicUsize AtomicIsize AtomicBool }
+
+#[stable(feature = "atomic_debug", since = "1.3.0")]
+impl<T> fmt::Debug for AtomicPtr<T> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.debug_tuple("AtomicPtr").field(&self.load(Ordering::SeqCst)).finish()
+    }
+}