Skip to content

Commit d1c487e

Browse files
committed
Add an example to Wrapping's documentation.
1 parent 7a0ccc4 commit d1c487e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/libcore/num/mod.rs

+11
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)