shape_core/utils/
mod.rs

1#![doc = include_str!("readme.md")]
2
3/// Returns the minimum of two values.
4#[inline(always)]
5pub fn min2<'a, 'b, 'c, T>(a: &'a T, b: &'b T) -> &'c T
6where
7    T: PartialOrd,
8    'a: 'c,
9    'b: 'c,
10{
11    if a < b { a } else { b }
12}
13/// Returns the maximum of two values.
14#[inline(always)]
15pub fn max2<'a, 'b, 'c, T>(a: &'a T, b: &'b T) -> &'c T
16where
17    T: PartialOrd,
18    'a: 'c,
19    'b: 'c,
20{
21    if a > b { a } else { b }
22}
23/// Returns the minimum of three values.
24#[inline(always)]
25pub fn min3<'a, 'b, 'c, 'd, T>(a: &'a T, b: &'b T, c: &'c T) -> &'d T
26where
27    T: PartialOrd,
28    'a: 'd,
29    'b: 'd,
30    'c: 'd,
31{
32    min2(min2(a, b), c)
33}
34/// Returns the maximum of three values.
35#[inline(always)]
36pub fn max3<'a, 'b, 'c, 'd, T>(a: &'a T, b: &'b T, c: &'c T) -> &'d T
37where
38    T: PartialOrd,
39    'a: 'd,
40    'b: 'd,
41    'c: 'd,
42{
43    max2(max2(a, b), c)
44}