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
This commit is contained in:
commit
aec36f61a0
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user