about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorAdolfo OchagavĂ­a <aochagavia92@gmail.com>2014-10-26 12:58:04 +0100
committerAdolfo OchagavĂ­a <aochagavia92@gmail.com>2014-10-26 15:30:40 +0100
commit79e05e999505a3ed4f3e4e1ed5e57deb39ebe485 (patch)
treebe811e6d712e9f9fac504f2aa2445202dd5001f4 /src/liballoc
parentcb943b7d2b179bdb0a97afedbbb092f1a7e7638c (diff)
downloadrust-79e05e999505a3ed4f3e4e1ed5e57deb39ebe485.tar.gz
rust-79e05e999505a3ed4f3e4e1ed5e57deb39ebe485.zip
Implement Show for `Arc<T>`
Fixes https://github.com/rust-lang/rust/issues/18299
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/arc.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs
index c447cb46c53..0e62fbb0144 100644
--- a/src/liballoc/arc.rs
+++ b/src/liballoc/arc.rs
@@ -15,6 +15,7 @@
 
 use core::atomic;
 use core::clone::Clone;
+use core::fmt::{mod, Show};
 use core::kinds::{Sync, Send};
 use core::mem::{min_align_of, size_of, drop};
 use core::mem;
@@ -147,6 +148,12 @@ impl<T: Send + Sync> Deref<T> for Arc<T> {
     }
 }
 
+impl<T: Send + Sync + Show> Show for Arc<T> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        (**self).fmt(f)
+    }
+}
+
 impl<T: Send + Sync + Clone> Arc<T> {
     /// Acquires a mutable pointer to the inner contents by guaranteeing that
     /// the reference count is one (no sharing is possible).
@@ -280,6 +287,7 @@ mod tests {
     use std::mem::drop;
     use std::ops::Drop;
     use std::option::{Option, Some, None};
+    use std::str::Str;
     use std::sync::atomic;
     use std::task;
     use std::vec::Vec;
@@ -426,4 +434,10 @@ mod tests {
         assert!(canary.load(atomic::Acquire) == 1);
         drop(arc_weak);
     }
+
+    #[test]
+    fn show_arc() {
+        let a = Arc::new(5u32);
+        assert!(format!("{}", a).as_slice() == "5")
+    }
 }