const_str/__ctfe/
equal.rs

1pub struct Equal<T1, T2>(pub T1, pub T2);
2
3impl Equal<&[u8], &[u8]> {
4    pub const fn const_eval(&self) -> bool {
5        crate::bytes::equal(self.0, self.1)
6    }
7}
8
9impl<const L1: usize, const L2: usize> Equal<&[u8; L1], &[u8; L2]> {
10    pub const fn const_eval(&self) -> bool {
11        crate::bytes::equal(self.0, self.1)
12    }
13}
14
15impl Equal<&str, &str> {
16    pub const fn const_eval(&self) -> bool {
17        crate::str::equal(self.0, self.1)
18    }
19}
20
21/// Checks that two strings are equal.
22///
23/// This macro is [const-fn compatible](./index.html#const-fn-compatible).
24///
25/// # Examples
26///
27/// ```
28/// const A: &str = "hello";
29/// const B: &str = "world";
30/// const C: &str = "hello";
31/// const EQ_AB: bool = const_str::equal!(A, B);
32/// const EQ_AC: bool = const_str::equal!(A, C);
33/// assert_eq!([EQ_AB, EQ_AC], [false, true]);
34///
35#[macro_export]
36macro_rules! equal {
37    ($lhs: expr, $rhs: expr) => {
38        $crate::__ctfe::Equal($lhs, $rhs).const_eval()
39    };
40}