#[repr(transparent)]pub struct Compare<T>(pub T);Expand description
Provides comparing methods for T, most of them const.
It provides the non-const methods pclamp, pmax, pmin
for comparing PartialOrdered values.
It provides the following const methods for comparing primitives:
clamp, max, min, eq, ne, lt, le, gt, ge.
In the case of floating-point primitives:
- they use total ordering.
- they implement aditional methods:
is_positive,is_negative,is_finite,is_infinite,is_nan. - methods will only be const with the
unsafe_constfeature enabled.
Tuple Fields§
§0: TImplementations§
source§impl<T: PartialOrd> Compare<T>
impl<T: PartialOrd> Compare<T>
sourcepub fn pclamp(self, min: T, max: T) -> T
pub fn pclamp(self, min: T, max: T) -> T
Compares and returns a PartialOrdered value clamped between min and max.
§Examples
assert_eq![0.4, Compare(1.0).pclamp(0.2, 0.4)];
assert_eq![0.2, Compare(0.0).pclamp(0.2, 0.4)];source§impl Compare<u8>
impl Compare<u8>
sourcepub const fn clamp(self, min: u8, max: u8) -> u8
pub const fn clamp(self, min: u8, max: u8) -> u8
Compares and returns self clamped between min and max.
sourcepub const fn max(self, other: u8) -> u8
pub const fn max(self, other: u8) -> u8
Compares and returns the maximum between self and other.
source§impl Compare<u16>
impl Compare<u16>
sourcepub const fn clamp(self, min: u16, max: u16) -> u16
pub const fn clamp(self, min: u16, max: u16) -> u16
Compares and returns self clamped between min and max.
sourcepub const fn max(self, other: u16) -> u16
pub const fn max(self, other: u16) -> u16
Compares and returns the maximum between self and other.
source§impl Compare<u32>
impl Compare<u32>
sourcepub const fn clamp(self, min: u32, max: u32) -> u32
pub const fn clamp(self, min: u32, max: u32) -> u32
Compares and returns self clamped between min and max.
sourcepub const fn max(self, other: u32) -> u32
pub const fn max(self, other: u32) -> u32
Compares and returns the maximum between self and other.
source§impl Compare<u64>
impl Compare<u64>
sourcepub const fn clamp(self, min: u64, max: u64) -> u64
pub const fn clamp(self, min: u64, max: u64) -> u64
Compares and returns self clamped between min and max.
sourcepub const fn max(self, other: u64) -> u64
pub const fn max(self, other: u64) -> u64
Compares and returns the maximum between self and other.
source§impl Compare<u128>
impl Compare<u128>
sourcepub const fn clamp(self, min: u128, max: u128) -> u128
pub const fn clamp(self, min: u128, max: u128) -> u128
Compares and returns self clamped between min and max.
sourcepub const fn max(self, other: u128) -> u128
pub const fn max(self, other: u128) -> u128
Compares and returns the maximum between self and other.
source§impl Compare<usize>
impl Compare<usize>
sourcepub const fn clamp(self, min: usize, max: usize) -> usize
pub const fn clamp(self, min: usize, max: usize) -> usize
Compares and returns self clamped between min and max.
sourcepub const fn max(self, other: usize) -> usize
pub const fn max(self, other: usize) -> usize
Compares and returns the maximum between self and other.
source§impl Compare<i8>
impl Compare<i8>
sourcepub const fn clamp(self, min: i8, max: i8) -> i8
pub const fn clamp(self, min: i8, max: i8) -> i8
Compares and returns self clamped between min and max.
sourcepub const fn max(self, other: i8) -> i8
pub const fn max(self, other: i8) -> i8
Compares and returns the maximum between self and other.
source§impl Compare<i16>
impl Compare<i16>
sourcepub const fn clamp(self, min: i16, max: i16) -> i16
pub const fn clamp(self, min: i16, max: i16) -> i16
Compares and returns self clamped between min and max.
sourcepub const fn max(self, other: i16) -> i16
pub const fn max(self, other: i16) -> i16
Compares and returns the maximum between self and other.
source§impl Compare<i32>
impl Compare<i32>
sourcepub const fn clamp(self, min: i32, max: i32) -> i32
pub const fn clamp(self, min: i32, max: i32) -> i32
Compares and returns self clamped between min and max.
sourcepub const fn max(self, other: i32) -> i32
pub const fn max(self, other: i32) -> i32
Compares and returns the maximum between self and other.
source§impl Compare<i64>
impl Compare<i64>
sourcepub const fn clamp(self, min: i64, max: i64) -> i64
pub const fn clamp(self, min: i64, max: i64) -> i64
Compares and returns self clamped between min and max.
sourcepub const fn max(self, other: i64) -> i64
pub const fn max(self, other: i64) -> i64
Compares and returns the maximum between self and other.
source§impl Compare<i128>
impl Compare<i128>
sourcepub const fn clamp(self, min: i128, max: i128) -> i128
pub const fn clamp(self, min: i128, max: i128) -> i128
Compares and returns self clamped between min and max.
sourcepub const fn max(self, other: i128) -> i128
pub const fn max(self, other: i128) -> i128
Compares and returns the maximum between self and other.
source§impl Compare<isize>
impl Compare<isize>
sourcepub const fn clamp(self, min: isize, max: isize) -> isize
pub const fn clamp(self, min: isize, max: isize) -> isize
Compares and returns self clamped between min and max.
sourcepub const fn max(self, other: isize) -> isize
pub const fn max(self, other: isize) -> isize
Compares and returns the maximum between self and other.
source§impl Compare<f32>
impl Compare<f32>
sourcepub const fn max(self, other: f32) -> f32
pub const fn max(self, other: f32) -> f32
Compares and returns the total ordered maximum between self and other.
§Features
This function will only be const with the unsafe_const feature enabled.
§Examples
assert_eq![2.0, Compare(2.0f32).max(-1.0)];
assert_eq![2.0, Compare(1.0f32).max(2.0)];
assert_eq![0.0, Compare(-0.0f32).max(0.0)];
assert_eq![f32::INFINITY, Compare(f32::INFINITY).max(f32::NEG_INFINITY)];sourcepub const fn min(self, other: f32) -> f32
pub const fn min(self, other: f32) -> f32
Compares and returns the total ordered minimum between self and other.
§Features
This function will only be const with the unsafe_const feature enabled.
§Examples
assert_eq![-1.0, Compare(2.0f32).min(-1.0)];
assert_eq![1.0, Compare(1.0f32).min(2.0)];
assert_eq![-0.0, Compare(-0.0f32).min(0.0)];
assert_eq![f32::NEG_INFINITY, Compare(f32::INFINITY).min(f32::NEG_INFINITY)];sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Returns true if self is sign positive.
sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Returns true if self is sign negative.
sourcepub const fn is_infinite(self) -> bool
pub const fn is_infinite(self) -> bool
Returns true if self is infinite (either negative or positive).
sourcepub const fn is_subnormal(self) -> bool
pub const fn is_subnormal(self) -> bool
Returns true if self is subnormal.
source§impl Compare<f64>
impl Compare<f64>
sourcepub const fn max(self, other: f64) -> f64
pub const fn max(self, other: f64) -> f64
Compares and returns the total ordered maximum between self and other.
§Features
This function will only be const with the unsafe_const feature enabled.
§Examples
assert_eq![2.0, Compare(2.0f64).max(-1.0)];
assert_eq![2.0, Compare(1.0f64).max(2.0)];
assert_eq![0.0, Compare(-0.0f64).max(0.0)];
assert_eq![f64::INFINITY, Compare(f64::INFINITY).max(f64::NEG_INFINITY)];sourcepub const fn min(self, other: f64) -> f64
pub const fn min(self, other: f64) -> f64
Compares and returns the total ordered minimum between self and other.
§Features
This function will only be const with the unsafe_const feature enabled.
§Examples
assert_eq![-1.0, Compare(2.0f64).min(-1.0)];
assert_eq![1.0, Compare(1.0f64).min(2.0)];
assert_eq![-0.0, Compare(-0.0f64).min(0.0)];
assert_eq![f64::NEG_INFINITY, Compare(f64::INFINITY).min(f64::NEG_INFINITY)];sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Returns true if self is sign positive.
sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Returns true if self is sign negative.
sourcepub const fn is_infinite(self) -> bool
pub const fn is_infinite(self) -> bool
Returns true if self is infinite (either negative or positive).
sourcepub const fn is_subnormal(self) -> bool
pub const fn is_subnormal(self) -> bool
Returns true if self is subnormal.
Trait Implementations§
source§impl<T: Ord> Ord for Compare<T>
impl<T: Ord> Ord for Compare<T>
source§impl<T: PartialEq> PartialEq for Compare<T>
impl<T: PartialEq> PartialEq for Compare<T>
source§impl<T: PartialOrd> PartialOrd for Compare<T>
impl<T: PartialOrd> PartialOrd for Compare<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl<T: Copy> Copy for Compare<T>
impl<T: Eq> Eq for Compare<T>
Auto Trait Implementations§
impl<T> Freeze for Compare<T>where
T: Freeze,
impl<T> RefUnwindSafe for Compare<T>where
T: RefUnwindSafe,
impl<T> Send for Compare<T>where
T: Send,
impl<T> Sync for Compare<T>where
T: Sync,
impl<T> Unpin for Compare<T>where
T: Unpin,
impl<T> UnwindSafe for Compare<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> Also for T
impl<T> Also for T
source§impl<T, Res> Apply<Res> for Twhere
T: ?Sized,
impl<T, Res> Apply<Res> for Twhere
T: ?Sized,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> ByteSize for T
impl<T> ByteSize for T
source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<T> ExtAny for Twhere
T: Any,
impl<T> ExtAny for Twhere
T: Any,
source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
source§impl<T> Mem for Twhere
T: ?Sized,
impl<T> Mem for Twhere
T: ?Sized,
source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true if dropping values of this type matters.source§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self without running its destructor.source§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
self with other, returning the previous value of self.source§fn mem_take(&mut self) -> Selfwhere
Self: Default,
fn mem_take(&mut self) -> Selfwhere
Self: Default,
self with its default value, returning the previous value of self.source§fn mem_swap(&mut self, other: &mut Self)where
Self: Sized,
fn mem_swap(&mut self, other: &mut Self)where
Self: Sized,
self and other without deinitializing either one.source§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice only.