|
1 | 1 | use core::cmp::Ordering;
|
2 | 2 |
|
3 |
| -use objc2::{Encode, Encoding}; |
| 3 | +use objc2::{Encode, Encoding, RefEncode}; |
4 | 4 |
|
5 | 5 | #[repr(isize)]
|
6 |
| -#[derive(Clone, Copy)] |
| 6 | +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
7 | 7 | pub enum NSComparisonResult {
|
8 | 8 | Ascending = -1,
|
9 | 9 | Same = 0,
|
10 | 10 | Descending = 1,
|
11 | 11 | }
|
12 | 12 |
|
| 13 | +impl Default for NSComparisonResult { |
| 14 | + fn default() -> Self { |
| 15 | + Self::Same |
| 16 | + } |
| 17 | +} |
| 18 | + |
13 | 19 | unsafe impl Encode for NSComparisonResult {
|
14 | 20 | const ENCODING: Encoding<'static> = isize::ENCODING;
|
15 | 21 | }
|
16 | 22 |
|
17 |
| -impl NSComparisonResult { |
18 |
| - pub fn from_ordering(order: Ordering) -> NSComparisonResult { |
| 23 | +unsafe impl RefEncode for NSComparisonResult { |
| 24 | + const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&Self::ENCODING); |
| 25 | +} |
| 26 | + |
| 27 | +impl From<Ordering> for NSComparisonResult { |
| 28 | + fn from(order: Ordering) -> Self { |
19 | 29 | match order {
|
20 |
| - Ordering::Less => NSComparisonResult::Ascending, |
21 |
| - Ordering::Equal => NSComparisonResult::Same, |
22 |
| - Ordering::Greater => NSComparisonResult::Descending, |
| 30 | + Ordering::Less => Self::Ascending, |
| 31 | + Ordering::Equal => Self::Same, |
| 32 | + Ordering::Greater => Self::Descending, |
23 | 33 | }
|
24 | 34 | }
|
| 35 | +} |
25 | 36 |
|
26 |
| - pub fn as_ordering(&self) -> Ordering { |
27 |
| - match *self { |
28 |
| - NSComparisonResult::Ascending => Ordering::Less, |
29 |
| - NSComparisonResult::Same => Ordering::Equal, |
30 |
| - NSComparisonResult::Descending => Ordering::Greater, |
| 37 | +impl From<NSComparisonResult> for Ordering { |
| 38 | + fn from(comparison_result: NSComparisonResult) -> Self { |
| 39 | + match comparison_result { |
| 40 | + NSComparisonResult::Ascending => Self::Less, |
| 41 | + NSComparisonResult::Same => Self::Equal, |
| 42 | + NSComparisonResult::Descending => Self::Greater, |
31 | 43 | }
|
32 | 44 | }
|
33 | 45 | }
|
0 commit comments