Trait konst::polymorphism::ConstCmpMarker [−][src]
cmp
only.Marker trait for types that implement the const comparison methods.
Implementors
Types that implement this trait are also expected to implement at least one of these inherent methods:
// use std::cmp::Ordering; const fn const_eq(&self, other: &Self) -> bool const fn const_cmp(&self, other: &Self) -> Ordering
Coercions
The Kind
and This
associated types
are used in the IsAConstCmpMarker
marker type
to automatically wrap types in CmpWrapper
if they’re from the standard library,
otherwise leaving them unwrapped.
Example
Manual Implementation
use konst::{ polymorphism::{ConstCmpMarker, IsNotStdKind}, const_cmp, const_eq, try_equal, }; use std::cmp::Ordering; struct MyType { x: &'static str, y: &'static [u16], } impl ConstCmpMarker for MyType { // These are the only associated types you're expected to use in // impls for custom types. type Kind = IsNotStdKind; type This = Self; } impl MyType { pub const fn const_eq(&self, other: &Self) -> bool { const_eq!(self.x, other.x) && const_eq!(self.y, other.y) } pub const fn const_cmp(&self, other: &Self) -> Ordering { try_equal!(const_cmp!(self.x, other.x)); try_equal!(const_cmp!(self.y, other.y)) } } const CMPS: [(Ordering, bool); 4] = { let foo = MyType{x: "hello", y: &[3, 5, 8, 13]}; let bar = MyType{x: "world", y: &[3, 5, 8, 13]}; [ (const_cmp!(foo, foo), const_eq!(foo, foo)), (const_cmp!(foo, bar), const_eq!(foo, bar)), (const_cmp!(bar, foo), const_eq!(bar, foo)), (const_cmp!(bar, bar), const_eq!(bar, bar)), ] }; assert_eq!( CMPS, [ (Ordering::Equal, true), (Ordering::Less, false), (Ordering::Greater, false), (Ordering::Equal, true), ] );
ìmpl_cmp
-based Implementation
You can use impl_cmp
to implement this trait,
as well as define the same methods for
multiple implementations with different type arguments.
use konst::{const_cmp, const_eq, impl_cmp, try_equal}; use std::cmp::Ordering; struct MyType<'a, T> { x: &'a str, y: &'a [T], } impl_cmp!{ // The comparison functions are only implemented for these types. impl['a] MyType<'a, bool>; impl['a] MyType<'a, u16>; impl['a] MyType<'a, &'static str>; pub const fn const_eq(&self, other: &Self) -> bool { const_eq!(self.x, other.x) && const_eq!(self.y, other.y) } pub const fn const_cmp(&self, other: &Self) -> Ordering { try_equal!(const_cmp!(self.x, other.x)); try_equal!(const_cmp!(self.y, other.y)) } } const CMPS: [(Ordering, bool); 4] = { let foo = MyType{x: "hello", y: &[3u16, 5, 8, 13]}; let bar = MyType{x: "world", y: &[3, 5, 8, 13]}; [ (const_cmp!(foo, foo), const_eq!(foo, foo)), (const_cmp!(foo, bar), const_eq!(foo, bar)), (const_cmp!(bar, foo), const_eq!(bar, foo)), (const_cmp!(bar, bar), const_eq!(bar, bar)), ] }; assert_eq!( CMPS, [ (Ordering::Equal, true), (Ordering::Less, false), (Ordering::Greater, false), (Ordering::Equal, true), ] );
Associated Types
type Kind
[src]
What kind of type this is, this can be one of:
-
IsArrayKind
: For slices, and arrays. -
IsStdKind
: Any other standard library type. -
IsNotStdKind
: Any type that is not from the standard library.
type This: ?Sized
[src]
The type after dereferencing,
implemented as type This = Self;
for all non-reference types
Implementations on Foreign Types
impl ConstCmpMarker for Option<u8>
[src]
impl ConstCmpMarker for Option<i8>
[src]
impl ConstCmpMarker for Option<u16>
[src]
impl ConstCmpMarker for Option<i16>
[src]
impl ConstCmpMarker for Option<u32>
[src]
impl ConstCmpMarker for Option<i32>
[src]
impl ConstCmpMarker for Option<u64>
[src]
impl ConstCmpMarker for Option<i64>
[src]
impl ConstCmpMarker for Option<u128>
[src]
impl ConstCmpMarker for Option<i128>
[src]
impl ConstCmpMarker for Option<usize>
[src]
impl ConstCmpMarker for Option<isize>
[src]
impl ConstCmpMarker for Option<bool>
[src]
impl ConstCmpMarker for Option<char>
[src]
impl ConstCmpMarker for Range<u8>
[src]
impl ConstCmpMarker for Range<u16>
[src]
impl ConstCmpMarker for Range<u32>
[src]
impl ConstCmpMarker for Range<u64>
[src]
impl ConstCmpMarker for Range<u128>
[src]
impl ConstCmpMarker for Range<usize>
[src]
impl ConstCmpMarker for Range<char>
[src]
impl ConstCmpMarker for RangeInclusive<u8>
[src]
impl ConstCmpMarker for RangeInclusive<u16>
[src]
impl ConstCmpMarker for RangeInclusive<u32>
[src]
impl ConstCmpMarker for RangeInclusive<u64>
[src]
impl ConstCmpMarker for RangeInclusive<u128>
[src]
impl ConstCmpMarker for RangeInclusive<usize>
[src]
impl ConstCmpMarker for RangeInclusive<char>
[src]
impl ConstCmpMarker for NonZeroU8
[src]
impl ConstCmpMarker for NonZeroI8
[src]
impl ConstCmpMarker for NonZeroU16
[src]
impl ConstCmpMarker for NonZeroI16
[src]
impl ConstCmpMarker for NonZeroU32
[src]
impl ConstCmpMarker for NonZeroI32
[src]
impl ConstCmpMarker for NonZeroU64
[src]
impl ConstCmpMarker for NonZeroI64
[src]
impl ConstCmpMarker for NonZeroU128
[src]
impl ConstCmpMarker for NonZeroI128
[src]
impl ConstCmpMarker for NonZeroUsize
[src]
impl ConstCmpMarker for NonZeroIsize
[src]
impl ConstCmpMarker for Option<NonZeroU8>
[src]
impl ConstCmpMarker for Option<NonZeroI8>
[src]
impl ConstCmpMarker for Option<NonZeroU16>
[src]
impl ConstCmpMarker for Option<NonZeroI16>
[src]
impl ConstCmpMarker for Option<NonZeroU32>
[src]
impl ConstCmpMarker for Option<NonZeroI32>
[src]
impl ConstCmpMarker for Option<NonZeroU64>
[src]
impl ConstCmpMarker for Option<NonZeroI64>
[src]
impl ConstCmpMarker for Option<NonZeroU128>
[src]
impl ConstCmpMarker for Option<NonZeroI128>
[src]
impl ConstCmpMarker for Option<NonZeroUsize>
[src]
impl ConstCmpMarker for Option<NonZeroIsize>
[src]
impl ConstCmpMarker for Ordering
[src]
impl ConstCmpMarker for Option<Ordering>
[src]
impl<T> ConstCmpMarker for PhantomData<T>
[src]
impl ConstCmpMarker for PhantomPinned
[src]
impl<'a> ConstCmpMarker for Option<&'a [u8]>
[src]
impl<'a> ConstCmpMarker for Option<&'a [u16]>
[src]
impl<'a> ConstCmpMarker for Option<&'a [u32]>
[src]
impl<'a> ConstCmpMarker for Option<&'a [u64]>
[src]
impl<'a> ConstCmpMarker for Option<&'a [u128]>
[src]
impl<'a> ConstCmpMarker for Option<&'a [i8]>
[src]
impl<'a> ConstCmpMarker for Option<&'a [i16]>
[src]
impl<'a> ConstCmpMarker for Option<&'a [i32]>
[src]
impl<'a> ConstCmpMarker for Option<&'a [i64]>
[src]
impl<'a> ConstCmpMarker for Option<&'a [i128]>
[src]
impl<'a> ConstCmpMarker for Option<&'a [bool]>
[src]
impl<'a> ConstCmpMarker for Option<&'a [char]>
[src]
impl<'a, 'b> ConstCmpMarker for Option<&'a [&'b str]>
[src]
impl<'a, 'b> ConstCmpMarker for Option<&'a [&'b [u8]]>
[src]
impl<'a> ConstCmpMarker for Option<&'a str>
[src]
type Kind = IsStdKind
cmp
only.type This = Self
cmp
only.Implementors
impl ConstCmpMarker for bool
[src]
impl ConstCmpMarker for char
[src]
impl ConstCmpMarker for i8
[src]
impl ConstCmpMarker for i16
[src]
impl ConstCmpMarker for i32
[src]
impl ConstCmpMarker for i64
[src]
impl ConstCmpMarker for i128
[src]
impl ConstCmpMarker for isize
[src]
impl ConstCmpMarker for str
[src]
impl ConstCmpMarker for u8
[src]
impl ConstCmpMarker for u16
[src]
impl ConstCmpMarker for u32
[src]
impl ConstCmpMarker for u64
[src]
impl ConstCmpMarker for u128
[src]
impl ConstCmpMarker for usize
[src]
impl<P> ConstCmpMarker for CmpWrapper<P>
[src]
type Kind = IsNotStdKind
type This = Self
impl<T> ConstCmpMarker for [T; 0]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 1]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 2]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 3]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 4]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 5]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 6]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 7]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 8]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 9]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 10]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 11]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 12]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 13]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 14]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 15]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 16]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 17]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 18]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 19]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 20]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 21]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 22]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 23]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 24]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 25]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 26]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 27]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 28]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 29]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 30]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 31]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T; 32]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> ConstCmpMarker for [T]
[src]
type Kind = IsArrayKind<T>
type This = [T]
impl<T: ?Sized> ConstCmpMarker for &T where
T: ConstCmpMarker,
[src]
T: ConstCmpMarker,
impl<T: ?Sized> ConstCmpMarker for &mut T where
T: ConstCmpMarker,
[src]
T: ConstCmpMarker,