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-saturating aritmethic on `T`.
/// Provides intentionally-saturating arithmetic on `T`.
///
/// Saturating arithmetic can be achieved either through methods like
/// `saturating_add`, or through the `Saturating<T>` type, which says that
/// all standard arithmetic operations on the underlying value are
/// intended to have saturating semantics.
///
/// The underlying value can be retrieved through the `.0` index of the
/// `Saturating` tuple.
///
/// # Layout
///
/// `Saturating<T>` is guaranteed to have the same layout and ABI as `T`.
///
/// # Example
///
/// ```
/// use constrained_int::i8::ConstrainedI8;
/// use constrained_int::Saturating;
///
/// // Default set to 0.
/// type Saturated = Saturating<ConstrainedI8<-10, 12, 0>>;
///
/// let mut saturated = Saturated::default();
/// saturated += 13;
/// assert_eq!(saturated.0.get(), 12);
///
/// saturated = saturated - saturated - saturated;
/// assert_eq!(saturated.0.get(), -10);
/// ```
;
// Implements common traits for `Saturating<T>` when the generic T implements them.
arithmetic_wrapper_traits_impl!
// Implements APIs for `Saturating<T>` where T is a unsigned constrained interger.
saturating_uint!
// Implements APIs for `Saturating<T>` where T is a signed constrained interger.
saturating_int!