Skip to content

Commit 7125a48

Browse files
committed
Move Wrapping<T> definition to wrapping mod
1 parent baecad9 commit 7125a48

File tree

2 files changed

+82
-75
lines changed

2 files changed

+82
-75
lines changed

library/core/src/num/mod.rs

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -34,79 +34,6 @@ macro_rules! doc_comment {
3434
};
3535
}
3636

37-
/// Provides intentionally-wrapped arithmetic on `T`.
38-
///
39-
/// Operations like `+` on `u32` values are intended to never overflow,
40-
/// and in some debug configurations overflow is detected and results
41-
/// in a panic. While most arithmetic falls into this category, some
42-
/// code explicitly expects and relies upon modular arithmetic (e.g.,
43-
/// hashing).
44-
///
45-
/// Wrapping arithmetic can be achieved either through methods like
46-
/// `wrapping_add`, or through the `Wrapping<T>` type, which says that
47-
/// all standard arithmetic operations on the underlying value are
48-
/// intended to have wrapping semantics.
49-
///
50-
/// The underlying value can be retrieved through the `.0` index of the
51-
/// `Wrapping` tuple.
52-
///
53-
/// # Examples
54-
///
55-
/// ```
56-
/// use std::num::Wrapping;
57-
///
58-
/// let zero = Wrapping(0u32);
59-
/// let one = Wrapping(1u32);
60-
///
61-
/// assert_eq!(u32::MAX, (zero - one).0);
62-
/// ```
63-
#[stable(feature = "rust1", since = "1.0.0")]
64-
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)]
65-
#[repr(transparent)]
66-
pub struct Wrapping<T>(#[stable(feature = "rust1", since = "1.0.0")] pub T);
67-
68-
#[stable(feature = "rust1", since = "1.0.0")]
69-
impl<T: fmt::Debug> fmt::Debug for Wrapping<T> {
70-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71-
self.0.fmt(f)
72-
}
73-
}
74-
75-
#[stable(feature = "wrapping_display", since = "1.10.0")]
76-
impl<T: fmt::Display> fmt::Display for Wrapping<T> {
77-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
78-
self.0.fmt(f)
79-
}
80-
}
81-
82-
#[stable(feature = "wrapping_fmt", since = "1.11.0")]
83-
impl<T: fmt::Binary> fmt::Binary for Wrapping<T> {
84-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
85-
self.0.fmt(f)
86-
}
87-
}
88-
89-
#[stable(feature = "wrapping_fmt", since = "1.11.0")]
90-
impl<T: fmt::Octal> fmt::Octal for Wrapping<T> {
91-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
92-
self.0.fmt(f)
93-
}
94-
}
95-
96-
#[stable(feature = "wrapping_fmt", since = "1.11.0")]
97-
impl<T: fmt::LowerHex> fmt::LowerHex for Wrapping<T> {
98-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
99-
self.0.fmt(f)
100-
}
101-
}
102-
103-
#[stable(feature = "wrapping_fmt", since = "1.11.0")]
104-
impl<T: fmt::UpperHex> fmt::UpperHex for Wrapping<T> {
105-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
106-
self.0.fmt(f)
107-
}
108-
}
109-
11037
// All these modules are technically private and only exposed for coretests:
11138
pub mod bignum;
11239
pub mod dec2flt;
@@ -116,6 +43,9 @@ pub mod flt2dec;
11643
mod nonzero;
11744
mod wrapping;
11845

46+
#[stable(feature = "rust1", since = "1.0.0")]
47+
pub use wrapping::Wrapping;
48+
11949
#[stable(feature = "nonzero", since = "1.28.0")]
12050
pub use nonzero::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
12151

library/core/src/num/wrapping.rs

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,83 @@
1-
use super::Wrapping;
1+
//! Definitions of `Wrapping<T>`.
2+
3+
use crate::fmt;
4+
use crate::ops::{Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign};
5+
use crate::ops::{BitXor, BitXorAssign, Div, DivAssign};
6+
use crate::ops::{Mul, MulAssign, Neg, Not, Rem, RemAssign};
7+
use crate::ops::{Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign};
8+
9+
/// Provides intentionally-wrapped arithmetic on `T`.
10+
///
11+
/// Operations like `+` on `u32` values are intended to never overflow,
12+
/// and in some debug configurations overflow is detected and results
13+
/// in a panic. While most arithmetic falls into this category, some
14+
/// code explicitly expects and relies upon modular arithmetic (e.g.,
15+
/// hashing).
16+
///
17+
/// Wrapping arithmetic can be achieved either through methods like
18+
/// `wrapping_add`, or through the `Wrapping<T>` type, which says that
19+
/// all standard arithmetic operations on the underlying value are
20+
/// intended to have wrapping semantics.
21+
///
22+
/// The underlying value can be retrieved through the `.0` index of the
23+
/// `Wrapping` tuple.
24+
///
25+
/// # Examples
26+
///
27+
/// ```
28+
/// use std::num::Wrapping;
29+
///
30+
/// let zero = Wrapping(0u32);
31+
/// let one = Wrapping(1u32);
32+
///
33+
/// assert_eq!(u32::MAX, (zero - one).0);
34+
/// ```
35+
#[stable(feature = "rust1", since = "1.0.0")]
36+
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)]
37+
#[repr(transparent)]
38+
pub struct Wrapping<T>(#[stable(feature = "rust1", since = "1.0.0")] pub T);
39+
40+
#[stable(feature = "rust1", since = "1.0.0")]
41+
impl<T: fmt::Debug> fmt::Debug for Wrapping<T> {
42+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43+
self.0.fmt(f)
44+
}
45+
}
46+
47+
#[stable(feature = "wrapping_display", since = "1.10.0")]
48+
impl<T: fmt::Display> fmt::Display for Wrapping<T> {
49+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50+
self.0.fmt(f)
51+
}
52+
}
53+
54+
#[stable(feature = "wrapping_fmt", since = "1.11.0")]
55+
impl<T: fmt::Binary> fmt::Binary for Wrapping<T> {
56+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57+
self.0.fmt(f)
58+
}
59+
}
260

3-
use crate::ops::*;
61+
#[stable(feature = "wrapping_fmt", since = "1.11.0")]
62+
impl<T: fmt::Octal> fmt::Octal for Wrapping<T> {
63+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64+
self.0.fmt(f)
65+
}
66+
}
67+
68+
#[stable(feature = "wrapping_fmt", since = "1.11.0")]
69+
impl<T: fmt::LowerHex> fmt::LowerHex for Wrapping<T> {
70+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71+
self.0.fmt(f)
72+
}
73+
}
74+
75+
#[stable(feature = "wrapping_fmt", since = "1.11.0")]
76+
impl<T: fmt::UpperHex> fmt::UpperHex for Wrapping<T> {
77+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
78+
self.0.fmt(f)
79+
}
80+
}
481

582
#[allow(unused_macros)]
683
macro_rules! sh_impl_signed {

0 commit comments

Comments
 (0)