diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2016-05-07 15:35:18 -0400 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2016-05-07 15:35:18 -0400 |
| commit | aec36f61a02671e4239fbece4e66f15a709870f5 (patch) | |
| tree | 783f8f21f5d95b39e706bc6569a9cee9b6f342b3 /src/libcore/num | |
| parent | 0b8a3d5187a033b5d2d273f8e09133d357e2853f (diff) | |
| parent | d1c487e6c738ebaee576c03f711ed26a1117d7f1 (diff) | |
| download | rust-aec36f61a02671e4239fbece4e66f15a709870f5.tar.gz rust-aec36f61a02671e4239fbece4e66f15a709870f5.zip | |
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
Diffstat (limited to 'src/libcore/num')
| -rw-r--r-- | src/libcore/num/mod.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 589ac90b308..af4ac482cf7 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -37,6 +37,17 @@ use slice::SliceExt; /// `wrapping_add`, or through the `Wrapping<T>` type, which says that /// all standard arithmetic operations on the underlying value are /// intended to have wrapping semantics. +/// +/// # Examples +/// +/// ``` +/// use std::num::Wrapping; +/// +/// let zero = Wrapping(0u32); +/// let one = Wrapping(1u32); +/// +/// assert_eq!(std::u32::MAX, (zero - one).0); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)] pub struct Wrapping<T>(#[stable(feature = "rust1", since = "1.0.0")] pub T); |
