Closed
Description
What it does
A few days ago i opened #11901
You could do this for the min()
method too.
So 0.min(<anything>)
is always zero if <anything>
is an unsigned integer.
Also this method is symmetric, that means same applies to <anything>.min(0)
.
You could go even further and generalize this to T::MIN.min(<anything>)
(where T
is any type of integer like i.e. i64
) is always T::MIN
.
And you could do this with the upper bound too: T::MAX.min(<anything>)
is for any integer type T
the same as <anything>
.
Advantage
- Remove of unnecessary function call
- Reduction of Code Complexity
Drawbacks
No response
Example
// example with zero and unsigned Type
let a = 0.min(42_usize);
// example with MIN and signed Type
let a = 42.min(i64::MIN);
// example with MAX and signed Type
let a = i32::MAX.min(9);
Could be written as:
// example with zero and unsigned Type
let a = 0;
// example with MIN and signed Type
let a = i64::MIN;
// example with MAX and signed Type
let a = 9;