Skip to main content

ConstMidpoint

Trait ConstMidpoint 

Source
pub trait ConstMidpoint: Sized {
    // Required method
    fn midpoint(self, rhs: Self) -> Self;
}
Expand description

Const-compatible midpoint calculation.

Computes the average of two values, rounded down, without overflow. Stable since Rust 1.85.0.

Required Methods§

Source

fn midpoint(self, rhs: Self) -> Self

Calculates the midpoint (average) of self and rhs, rounded down.

This never overflows, even for values close to the maximum.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ConstMidpoint for u8

Source§

fn midpoint(self, rhs: Self) -> Self

Source§

impl ConstMidpoint for u16

Source§

fn midpoint(self, rhs: Self) -> Self

Source§

impl ConstMidpoint for u32

Source§

fn midpoint(self, rhs: Self) -> Self

Source§

impl ConstMidpoint for u64

Source§

fn midpoint(self, rhs: Self) -> Self

Source§

impl ConstMidpoint for u128

Source§

fn midpoint(self, rhs: Self) -> Self

Implementors§

Source§

impl<T: ConstMachineWord + MachineWord, const N: usize> ConstMidpoint for FixedUInt<T, N>