Skip to content

Commit

Permalink
Implement Display and Hash for std::num::Wrapping
Browse files Browse the repository at this point in the history
Also, change the `Debug` implementation to only show the inner value.

Fixes #33006.
  • Loading branch information
tbu- committed Apr 16, 2016
1 parent 6fa61b8 commit 79e68a6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/libcore/num/mod.rs
Expand Up @@ -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<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:
Expand Down

0 comments on commit 79e68a6

Please sign in to comment.