From 79e68a61a90fc6631e22a1d81d275c6e658d4771 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Sat, 16 Apr 2016 09:51:21 +0200 Subject: [PATCH] Implement `Display` and `Hash` for `std::num::Wrapping` Also, change the `Debug` implementation to only show the inner value. Fixes #33006. --- src/libcore/num/mod.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 9af8ef53851..ee5ed376849 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -38,9 +38,23 @@ use slice::SliceExt; /// 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(#[stable(feature = "rust1", since = "1.0.0")] pub T); +#[stable(feature = "rust1", since = "1.0.0")] +impl fmt::Debug for Wrapping { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f) + } +} + +#[stable(feature = "wrapping_display", since = "1.10.0")] +impl fmt::Display for Wrapping { + 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: