1pub(crate) mod opt {
2/// Get an [Option] with the maximum value, compared between the passed in value and the inner
3 /// value of the [Option]. If the [Option] is `None`, then an option containing the passed in
4 /// value will be returned.
5pub(crate) fn max<T: Ord + Copy>(a: Option<T>, b: T) -> Option<T> {
6a.map_or(Some(b), |v| Some(std::cmp::max(v, b)))
7 }
89/// Get an [Option] with the minimum value, compared between the passed in value and the inner
10 /// value of the [Option]. If the [Option] is `None`, then an option containing the passed in
11 /// value will be returned.
12pub(crate) fn min<T: Ord + Copy>(a: Option<T>, b: T) -> Option<T> {
13a.map_or(Some(b), |v| Some(std::cmp::min(v, b)))
14 }
1516#[cfg(test)]
17mod tests {
18use super::*;
1920#[test]
21fn opt_max() {
22assert_eq!(max(None, 5), Some(5));
23assert_eq!(max(Some(1), 5), Some(5));
24assert_eq!(max(Some(10), 5), Some(10));
25 }
2627#[test]
28fn opt_min() {
29assert_eq!(min(None, 5), Some(5));
30assert_eq!(min(Some(1), 5), Some(1));
31assert_eq!(min(Some(10), 5), Some(5));
32 }
33 }
34}