Skip to content

Commit 5fc8065

Browse files
committed
Rollup merge of #33023 - tbu-:pr_wrapping_traits, r=alexcrichton
Implement `Display` and `Hash` for `std::num::Wrapping` Also, change the `Debug` implementation to only show the inner value. Fixes #33006.
2 parents 51c3c43 + 79e68a6 commit 5fc8065

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/libcore/num/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,23 @@ use slice::SliceExt;
3838
/// all standard arithmetic operations on the underlying value are
3939
/// intended to have wrapping semantics.
4040
#[stable(feature = "rust1", since = "1.0.0")]
41-
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug, Default)]
41+
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)]
4242
pub struct Wrapping<T>(#[stable(feature = "rust1", since = "1.0.0")] pub T);
4343

44+
#[stable(feature = "rust1", since = "1.0.0")]
45+
impl<T: fmt::Debug> fmt::Debug for Wrapping<T> {
46+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
47+
self.0.fmt(f)
48+
}
49+
}
50+
51+
#[stable(feature = "wrapping_display", since = "1.10.0")]
52+
impl<T: fmt::Display> fmt::Display for Wrapping<T> {
53+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
54+
self.0.fmt(f)
55+
}
56+
}
57+
4458
mod wrapping;
4559

4660
// All these modules are technically private and only exposed for libcoretest:

0 commit comments

Comments
 (0)