Trait CheckedMapRange

Source
pub trait CheckedMapRange: Sized {
    // Required method
    fn checked_map_range(
        self,
        from: Range<Self>,
        to: Range<Self>,
    ) -> Option<Self>;
}
Expand description

Mapping a value from range from to another range to.

This is a checked version of MapRange

§Examples

let a = 10_u32.checked_map_range(0..5, 5..2);
let b = 10_u32.checked_map_range(0..5, 2..5);

assert_eq!(a, None);
assert_eq!(b, Some(8));

Required Methods§

Source

fn checked_map_range(self, from: Range<Self>, to: Range<Self>) -> Option<Self>

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.

Implementors§

Source§

impl<T> CheckedMapRange for T
where T: CheckedAdd<Output = Self> + CheckedSub<Output = Self> + CheckedMul<Output = Self> + CheckedDiv<Output = Self>,