Clamper32

Struct Clamper32 

Source
pub struct Clamper32;
Expand description

Clamps a distance to half the range of an i32.

It makes sure to clamp to the minimum or maximum representable value in the new bit-size, under the new range-limit conditions.

Implementations§

Source§

impl Clamper32

Source

pub const MIN: i32 = -1_073_741_824i32

Minimum value for any layout dimension.

Source

pub const MAX: i32 = 1_073_741_823i32

Maximum value for any layout dimension.

Source

pub const fn clamp(d: i32) -> i32

Clamps i32 distance to MIN..MAX.

This function clamps a value using the same primitive type.

It is simpler and probably faster than the other clamping functions with the bit-size in the name.

Source

pub const fn clamp_non_negative(d: i32) -> i32

Clamps i32 distance to 0..MAX.

This function clamps a value using the same primitive type.

It is simpler and probably faster than the other clamping functions with the bit-size in the name.

Source

pub const fn clamp_positive(d: i32) -> i32

Clamps i32 distance to 1..MAX.

This function clamps a value using the same primitive type.

It is simpler and probably faster than the other clamping functions with the bit-size in the name.

Source

pub const fn clamp_from_i32(d: i32) -> i32

Clamps i32 distance to i32 MIN..MAX.

Source

pub const fn clamp_non_negative_from_i32(d: i32) -> i32

Clamps i32 distance to i32 0..MAX.

Source

pub const fn clamp_positive_from_i32(d: i32) -> i32

Clamps i32 distance to i32 1..MAX.

Source

pub const fn clamp_to_i32(d: i32) -> i32

Clamps i32 distance to i32 MIN..MAX.

Source

pub const fn clamp_non_negative_to_i32(d: i32) -> i32

Clamps i32 distance to i32 0..MAX.

Source

pub const fn clamp_positive_to_i32(d: i32) -> i32

Clamps i32 distance to i32 1..MAX.

Source

pub const fn clamp_from_u32(d: u32) -> i32

Clamps an u32 distance to i32 0..MAX.

Source

pub const fn clamp_positive_from_u32(d: u32) -> i32

Clamps u32 distance to i32 1..MAX.

Source

pub const fn clamp_to_u32(d: i32) -> u32

Clamps i32 distance to u32 0..MAX.

Source

pub const fn clamp_positive_to_u32(d: i32) -> u32

Clamps i32 distance to u32 1..MAX.

Source

pub const fn clamp_from_u16(d: u16) -> i32

Clamps u16 distance to i32 0..MAX.

Source

pub const fn clamp_positive_from_u16(d: u16) -> i32

Clamps u16 distance to i32 1..MAX.

Source

pub const fn clamp_to_u16(d: i32) -> u16

Clamps i32 distance to u16 0..MAX.

Source

pub const fn clamp_positive_to_u16(d: i32) -> u16

Clamps i32 distance to u16 1..MAX.

Source

pub const fn clamp_from_i16(d: i16) -> i32

Clamps i16 distance to i32 MIN..MAX.

Source

pub const fn clamp_non_negative_from_i16(d: i16) -> i32

Clamps i16 distance to i32 0..MAX.

Source

pub const fn clamp_positive_from_i16(d: i16) -> i32

Clamps i16 distance to i32 1..MAX.

Source

pub const fn clamp_to_i16(d: i32) -> i16

Clamps i32 distance to i16 MIN..MAX.

Source

pub const fn clamp_non_negative_to_i16(d: i32) -> i16

Clamps i32 distance to i16 0..MAX.

Source

pub const fn clamp_positive_to_i16(d: i32) -> i16

Clamps i32 distance to i16 1..MAX.

Source

pub const fn clamp_from_usize(d: usize) -> i32

Clamps usize distance to i32 0..MAX.

Source

pub const fn clamp_positive_from_usize(d: usize) -> i32

Clamps usize distance to i32 1..MAX.

Source

pub const fn clamp_to_usize(d: i32) -> usize

Clamps i32 distance to usize 0..MAX.

Source

pub const fn clamp_positive_to_usize(d: i32) -> usize

Clamps i32 distance to usize 1..MAX.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.