monero_primitives/
bounds.rs

1/*
2  These structs exist just to consolidate documentation. We define these bounds in several places
3  and copying these docstrings would be very annoying.
4*/
5
6/// A `const`-context variant of the `max` function.
7///
8/// This is hidden as it's not to be considered part of our API commitment and is not guaranteed to
9/// be available/usable. It's implemented as a macro to work with any type, as we can't express an
10/// `Ord` bound within a `const` context.
11#[doc(hidden)]
12#[macro_export]
13macro_rules! const_max {
14  ($a: expr, $b: expr) => {
15    if $a > $b {
16      $a
17    } else {
18      $b
19    }
20  };
21}
22
23/// A `const`-context variant of the `min` function.
24///
25/// This is hidden as it's not to be considered part of our API commitment and is not guaranteed to
26/// be available/usable. It's implemented as a macro to work with any type, as we can't express an
27/// `Ord` bound within a `const` context.
28#[doc(hidden)]
29#[macro_export]
30macro_rules! const_min {
31  ($a: expr, $b: expr) => {
32    if $a < $b {
33      $a
34    } else {
35      $b
36    }
37  };
38}
39
40/// An upper bound for a value.
41///
42/// This is not guaranteed to be the minimal upper bound, solely a correct bound. This is not
43/// guaranteed to be a bound stable throughout the lifetime of the entire Monero protocol, solely
44/// as of the targeted version of the Monero protocol. It is intended to be used for size hints.
45/// Changes to this value, whether decreasing it to be closer to the actual bound or increasing it
46/// in response to a new version of the protocol, will not be considered breaking changes under
47/// SemVer.
48pub struct UpperBound<U>(pub U);
49
50/// A lower bound for a value.
51///
52/// This is not guaranteed to be the maximal lower bound, solely a correct bound (meaning `0` would
53/// always be acceptable). This is not guaranteed to be a bound stable throughout the lifetime of
54/// the entire Monero protocol, solely as of the targeted version of the Monero protocol. It is
55/// intended to be used for size hints. Changes to this value, whether increasing it to be closer
56/// to the actual bound or decreasing it in response to a new version of the protocol, will not be
57/// considered breaking changes under SemVer.
58pub struct LowerBound<U>(pub U);