tstr/macros/
cmp_macros.rs

1/// For comparing [`TStr`] types for equality, using [`TStrEq::EQ`].
2///
3/// # Example
4///
5/// ```rust
6/// use tstr::{TS, tstr_eq};
7///
8/// assert!( tstr_eq!(TS!("foo"), TS!("foo")));
9/// assert!(!tstr_eq!(TS!("foo"), TS!("bar")));
10///
11/// type Foo = TS!("foo");
12/// type Bar = TS!("bar");
13///
14/// assert!( tstr_eq!(Foo, Foo));
15/// assert!(!tstr_eq!(Foo, Bar));
16/// ```
17///
18/// [`TStrEq::EQ`]: ./trait.TStrEq.html#associatedconstant.EQ
19/// [`TStr`]: ./struct.TStr.html
20///
21#[macro_export]
22#[cfg(feature = "cmp_traits")]
23macro_rules! tstr_eq {
24    ($left:ty, $right:ty $(,)*) => {
25        <$left as $crate::TStrEq<$right>>::EQ
26    };
27}
28
29/// For comparing [`TStr`] types for inequality, using [`TStrEq::NE`]
30///
31/// # Example
32///
33/// ```rust
34/// use tstr::{TS, tstr_ne};
35///
36/// assert!(!tstr_ne!(TS!("foo"), TS!("foo")));
37/// assert!( tstr_ne!(TS!("foo"), TS!("bar")));
38///
39/// type Foo = TS!("foo");
40/// type Bar = TS!("bar");
41///
42/// assert!(!tstr_ne!(Foo, Foo));
43/// assert!( tstr_ne!(Foo, Bar));
44/// ```
45///
46/// [`TStrEq::NE`]: ./trait.TStrEq.html#associatedconstant.NE
47/// [`TStr`]: ./struct.TStr.html
48#[macro_export]
49#[cfg(feature = "cmp_traits")]
50macro_rules! tstr_ne {
51    ($left:ty, $right:ty $(,)*) => {
52        <$left as $crate::TStrEq<$right>>::NE
53    };
54}
55
56/// For comparing [`TStr`] types for ordering, using [`TStrOrd::CMP`]
57///
58/// # Example
59///
60/// ```rust
61/// use tstr::{TS, tstr_cmp};
62///
63/// use std::cmp::Ordering;
64///
65/// type Aaa = TS!(Aaa);
66/// type Bbb = TS!(Bbb);
67/// type Ccc = TS!(Ccc);
68///
69/// assert_eq!(tstr_cmp!(Bbb, Ccc), Ordering::Less);
70/// assert_eq!(tstr_cmp!(Bbb, Bbb), Ordering::Equal);
71/// assert_eq!(tstr_cmp!(Bbb, Aaa), Ordering::Greater);
72/// ```
73///
74/// [`TStrOrd::CMP`]: ./trait.TStrOrd.html#associatedconstant.CMP
75/// [`TStr`]: ./struct.TStr.html
76#[cfg(feature = "const_generics")]
77#[macro_export]
78#[cfg(feature = "cmp_traits")]
79macro_rules! tstr_cmp {
80    ($left:ty, $right:ty $(,)*) => {
81        <$left as $crate::TStrOrd<$right>>::CMP
82    };
83}