Skip to content

Commit 8842100

Browse files
committed
Rollup merge of #33428 - fiveop:wrapping_example, r=steveklabnik
Add an example to Wrapping's documentation. Such an example would have helped me understand `Wrapping` quicker. r? @steveklabnik
2 parents 7860cc5 + d1c487e commit 8842100

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/libcore/num/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ use slice::SliceExt;
3737
/// `wrapping_add`, or through the `Wrapping<T>` type, which says that
3838
/// all standard arithmetic operations on the underlying value are
3939
/// intended to have wrapping semantics.
40+
///
41+
/// # Examples
42+
///
43+
/// ```
44+
/// use std::num::Wrapping;
45+
///
46+
/// let zero = Wrapping(0u32);
47+
/// let one = Wrapping(1u32);
48+
///
49+
/// assert_eq!(std::u32::MAX, (zero - one).0);
50+
/// ```
4051
#[stable(feature = "rust1", since = "1.0.0")]
4152
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)]
4253
pub struct Wrapping<T>(#[stable(feature = "rust1", since = "1.0.0")] pub T);

0 commit comments

Comments
 (0)