pub trait Midpoint: Sized {
type Output;
// Required method
fn midpoint(self, rhs: Self) -> Self::Output;
}Expand description
Computes the midpoint (average) of two values without overflowing.
Required Associated Types§
Sourcetype Output
type Output
Calculates the midpoint (self + rhs) / 2 as if it were performed in
a sufficiently-large type, so it never overflows. The result is
rounded towards zero.
use const_num_traits::Midpoint;
assert_eq!(Midpoint::midpoint(u8::MAX, u8::MAX), u8::MAX);
assert_eq!(Midpoint::midpoint(0u8, 7), 3);
assert_eq!(Midpoint::midpoint(-7i8, 0), -3);Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".