konst/other/
cmp.rs

1use core::{
2    cmp::Ordering,
3    marker::{PhantomData, PhantomPinned},
4};
5
6use crate::cmp::const_ord_macros::cmp_int;
7
8__delegate_const_eq! {
9    /// Compares two `Ordering` for equality.
10    #[inline]
11    pub const fn eq_ordering(copy left: Ordering, right: Ordering) -> bool {
12        left as i8 == right as i8
13    }
14}
15
16__delegate_const_ord! {
17    /// Compares two `Ordering`, returning the ordering of `left` relative to `right`.
18    #[inline]
19    pub const fn cmp_ordering(copy left: Ordering, right: Ordering) -> Ordering {
20        cmp_int!(left as i8, right as i8)
21    }
22}
23
24__declare_fns_with_docs! {
25    (Option<Ordering>, (eq_option_ordering, cmp_option_ordering))
26
27    docs(default)
28
29    macro = __impl_option_cmp_fns!(
30        params(l, r)
31        eq_comparison = eq_ordering(l, r),
32        cmp_comparison = cmp_ordering(l, r),
33        parameter_copyability = copy,
34    ),
35}
36
37macro_rules! impl_for_marker_traits{
38    (
39        ($type:ty, ($eq_fn_name:ident, $cmp_fn_name:ident) $(, for[$($generic:tt)*] )? )
40
41        docs( $docs_eq:expr, $docs_cmp:expr, )
42    ) => {
43        __delegate_const_eq! {
44            $(for[$($generic)*] )?
45            #[doc = $docs_eq]
46            #[inline]
47            pub const fn $eq_fn_name(copy _l: $type, _r: $type) -> bool {
48                true
49            }
50        }
51
52        __delegate_const_ord! {
53            $(for[$($generic)*] )?
54            #[doc = $docs_cmp]
55            #[inline]
56            pub const fn $cmp_fn_name(copy _l: $type, _r: $type) -> Ordering {
57                Ordering::Equal
58            }
59        }
60    }
61}
62
63__declare_fns_with_docs! {
64    (PhantomData<T>, (eq_phantomdata, cmp_phantomdata), for[T,])
65    (PhantomPinned, (eq_phantompinned, cmp_phantompinned))
66
67    docs(default)
68
69    macro = impl_for_marker_traits!(),
70}