1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! Container for intentionally-wrapped aritmethic on `T`.
/// Provides intentionally-wrapped arithmetic on `T`.
///
/// Wrapping arithmetic can be achieved either through methods like
/// `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.
///
/// The underlying value can be retrieved through the .0 index of the
/// Wrapping tuple.
///
/// # Layout
///
/// `Wrapping<T>` is guaranteed to have the same layout and ABI as `T`.
///
/// # Example
///
/// ```
/// use constrained_int::i8::ConstrainedI8;
/// use constrained_int::Wrapping;
///
/// // Default set to 0.
/// type Wrapped = Wrapping<ConstrainedI8<-10, 12, 0>>;
///
/// let mut wrapped = Wrapped::default();
/// wrapped += 13;
/// assert_eq!(wrapped.0.get(), -10);
///
/// wrapped = wrapped - wrapped;
/// assert_eq!(wrapped.0.get(), 0);
/// ```
;
// Implements common traits for `Wrapping<T>` if T implements them.
arithmetic_wrapper_traits_impl!
// Implements APIs for `Wrapping<T>` where T is a unsigned constrained interger.
wrapping_uint!
// Implements APIs for `Wrapping<T>` where T is a signed constrained integer.
wrapping_int!