fn a_plus_abs_b<
T: std::ops::Add +
std::ops::Sub<Output = <T as std::ops::Add>::Output> +
std::cmp::PartialOrd
>(a: T, b: T, zero: T) -> <T as std::ops::Add>::Output {
if b >= zero {
plus
} else {
minus
}(a, b)
}
You could probably provide a zero trait or use a preexisting one, but passing in a zero parameter is the most straightforward way, especially if you like relying on only the standard library. Not exactly the most idiomatic thing if you're using it often though, so perhaps the trait solution would scale the best.