#[repr(transparent)]pub struct Compare<T>(pub T);
Expand description
Provides comparing methods for T
.
It provides the non-const methods pclamp
, pmax
, pmin
for comparing PartialOrd
ered 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:
- total ordering is used.
- aditional methods are provided:
is_positive
,is_negative
,is_finite
,is_infinite
,is_nan
.
Tuple Fields§
§0: T
Implementations§
Source§impl<T: PartialOrd> Compare<T>
impl<T: PartialOrd> Compare<T>
Sourcepub fn pclamp(self, min: T, max: T) -> Option<T> ⓘ
pub fn pclamp(self, min: T, max: T) -> Option<T> ⓘ
Compares and returns a PartialOrd
ered value
clamped between min
and max
.
Returns None
if comparisons are indeterminate.
§Examples
assert_eq![Some(0.4), Compare(1.0).pclamp(0.2, 0.4)];
assert_eq![Some(0.2), Compare(0.0).pclamp(0.2, 0.4)];
//
assert_eq![None, Compare(1.0).pclamp(f32::NAN, f32::NAN)];
assert_eq![None, Compare(1.0).pclamp(f32::NAN, 0.4)];
assert_eq![None, Compare(1.0).pclamp(0.2, f32::NAN)];
Sourcepub fn pmax(self, other: T) -> Option<T> ⓘ
pub fn pmax(self, other: T) -> Option<T> ⓘ
Compares and returns the maximum of two PartialOrd
ered values.
Returns None
if comparisons are indeterminate.
Complements core::cmp::
max
which requires Ord
§Examples
assert_eq![Some(0.4), Compare(0.2).pmax(0.4)];
//
assert_eq![None, Compare(0.2).pmax(f32::NAN)];
assert_eq![None, Compare(f32::NAN).pmax(0.4)];
Sourcepub fn pmin(self, other: T) -> Option<T> ⓘ
pub fn pmin(self, other: T) -> Option<T> ⓘ
Compares and returns the minimum of two PartialOrd
ered values.
Returns None
if comparisons are indeterminate.
Complements core::cmp::
min
which requires Ord
§Example
assert_eq![Some(0.2), Compare(0.2).pmin(0.4)];
//
assert_eq![None, Compare(0.2).pmin(f32::NAN)];
assert_eq![None, Compare(f32::NAN).pmin(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 clamp(self, min: f32, max: f32) -> f32 ⓘ
pub const fn clamp(self, min: f32, max: f32) -> f32 ⓘ
Compares and returns a clamped total ordered self
between min
and max
.
§Examples
assert_eq![2.0, Compare(5.0f32).clamp(-1.0, 2.0)];
assert_eq![-1.0, Compare(-5.0f32).clamp(-1.0, 2.0)];
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
.
§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
.
§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 clamp(self, min: f64, max: f64) -> f64 ⓘ
pub const fn clamp(self, min: f64, max: f64) -> f64 ⓘ
Compares and returns a clamped total ordered self
between min
and max
.
§Examples
assert_eq![2.0, Compare(5.0f64).clamp(-1.0, 2.0)];
assert_eq![-1.0, Compare(-5.0f64).clamp(-1.0, 2.0)];
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
.
§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
.
§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.
Source§impl Compare<f16>
impl Compare<f16>
Sourcepub const fn total_cmp(self, other: f16) -> Ordering
pub const fn total_cmp(self, other: f16) -> Ordering
A (const
) port of f16::
[total_cmp
][f16#method.total_cmp].
Sourcepub const fn clamp(self, min: f16, max: f16) -> f16
pub const fn clamp(self, min: f16, max: f16) -> f16
Compares and returns a clamped total ordered self
between min
and max
.
§Examples
assert_eq![2.0, Compare(5.0f16).clamp(-1.0, 2.0)];
assert_eq![-1.0, Compare(-5.0f16).clamp(-1.0, 2.0)];
Sourcepub const fn max(self, other: f16) -> f16
pub const fn max(self, other: f16) -> f16
Compares and returns the total ordered maximum between self
and other
.
§Examples
assert_eq![2.0, Compare(2.0f16).max(-1.0)];
assert_eq![2.0, Compare(1.0f16).max(2.0)];
assert_eq![0.0, Compare(-0.0f16).max(0.0)];
assert_eq![f16::INFINITY, Compare(f16::INFINITY).max(f16::NEG_INFINITY)];
Sourcepub const fn min(self, other: f16) -> f16
pub const fn min(self, other: f16) -> f16
Compares and returns the total ordered minimum between self
and other
.
§Examples
assert_eq![-1.0, Compare(2.0f16).min(-1.0)];
assert_eq![1.0, Compare(1.0f16).min(2.0)];
assert_eq![-0.0, Compare(-0.0f16).min(0.0)];
assert_eq![f16::NEG_INFINITY, Compare(f16::INFINITY).min(f16::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<f128>
impl Compare<f128>
Sourcepub const fn total_cmp(self, other: f128) -> Ordering
pub const fn total_cmp(self, other: f128) -> Ordering
A (const
) port of f128::
[total_cmp
][f128#method.total_cmp].
Sourcepub const fn clamp(self, min: f128, max: f128) -> f128
pub const fn clamp(self, min: f128, max: f128) -> f128
Compares and returns a clamped total ordered self
between min
and max
.
§Examples
assert_eq![2.0, Compare(5.0f128).clamp(-1.0, 2.0)];
assert_eq![-1.0, Compare(-5.0f128).clamp(-1.0, 2.0)];
Sourcepub const fn max(self, other: f128) -> f128
pub const fn max(self, other: f128) -> f128
Compares and returns the total ordered maximum between self
and other
.
§Examples
assert_eq![2.0, Compare(2.0f128).max(-1.0)];
assert_eq![2.0, Compare(1.0f128).max(2.0)];
assert_eq![0.0, Compare(-0.0f128).max(0.0)];
assert_eq![f128::INFINITY, Compare(f128::INFINITY).max(f128::NEG_INFINITY)];
Sourcepub const fn min(self, other: f128) -> f128
pub const fn min(self, other: f128) -> f128
Compares and returns the total ordered minimum between self
and other
.
§Examples
assert_eq![-1.0, Compare(2.0f128).min(-1.0)];
assert_eq![1.0, Compare(1.0f128).min(2.0)];
assert_eq![-0.0, Compare(-0.0f128).min(0.0)];
assert_eq![f128::NEG_INFINITY, Compare(f128::INFINITY).min(f128::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: PartialOrd> PartialOrd for Compare<T>
impl<T: PartialOrd> PartialOrd for Compare<T>
impl<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§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize ⓘ
fn byte_align(&self) -> usize ⓘ
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> ExtAny for T
impl<T> ExtAny for T
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> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of_val(&self) -> usize ⓘ
fn mem_align_of_val(&self) -> usize ⓘ
Source§fn mem_size_of_val(&self) -> usize ⓘ
fn mem_size_of_val(&self) -> usize ⓘ
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out
indicating that a T
is niched.