micromap/set/
eq.rs

1// Copyright (c) 2023 Yegor Bugayenko
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included
11// in all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19// SOFTWARE.
20
21use crate::Set;
22
23impl<T: PartialEq, const N: usize> PartialEq for Set<T, N> {
24    /// Two sets can be compared.
25    ///
26    /// For example:
27    ///
28    /// ```
29    /// let mut m1: micromap::Set<u8, 10> = micromap::Set::new();
30    /// let mut m2: micromap::Set<u8, 10> = micromap::Set::new();
31    /// m1.insert(1);
32    /// m2.insert(1);
33    /// # #[cfg(std)]
34    /// assert_eq!(m1, m2);
35    /// // two sets with different order of key-value pairs are still equal:
36    /// m1.insert(2);
37    /// m1.insert(3);
38    /// m2.insert(3);
39    /// m2.insert(2);
40    /// # #[cfg(std)]
41    /// assert_eq!(m1, m2);
42    /// ```
43    #[inline]
44    fn eq(&self, other: &Self) -> bool {
45        self.map.eq(&other.map)
46    }
47}
48
49impl<T: Eq, const N: usize> Eq for Set<T, N> {}