]> git.lizzy.rs Git - rust.git/commitdiff
Implement `Display` and `Hash` for `std::num::Wrapping`
authorTobias Bucher <tobiasbucher5991@gmail.com>
Sat, 16 Apr 2016 07:51:21 +0000 (09:51 +0200)
committerTobias Bucher <tobiasbucher5991@gmail.com>
Sat, 16 Apr 2016 07:53:40 +0000 (09:53 +0200)
Also, change the `Debug` implementation to only show the inner value.

Fixes #33006.

src/libcore/num/mod.rs

index 9af8ef53851db986bc48556ebe74f3fa8c40eda7..ee5ed3768498f8519f22dfbdcee245caf0c9e333 100644 (file)
 /// all standard arithmetic operations on the underlying value are
 /// intended to have wrapping semantics.
 #[stable(feature = "rust1", since = "1.0.0")]
-#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug, Default)]
+#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)]
 pub struct Wrapping<T>(#[stable(feature = "rust1", since = "1.0.0")] pub T);
 
+#[stable(feature = "rust1", since = "1.0.0")]
+impl<T: fmt::Debug> fmt::Debug for Wrapping<T> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        self.0.fmt(f)
+    }
+}
+
+#[stable(feature = "wrapping_display", since = "1.10.0")]
+impl<T: fmt::Display> fmt::Display for Wrapping<T> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        self.0.fmt(f)
+    }
+}
+
 mod wrapping;
 
 // All these modules are technically private and only exposed for libcoretest: