-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
25 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,45 @@ | ||
use core::cmp::Ordering; | ||
|
||
use objc2::{Encode, Encoding}; | ||
use objc2::{Encode, Encoding, RefEncode}; | ||
|
||
#[repr(isize)] | ||
#[derive(Clone, Copy)] | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
pub enum NSComparisonResult { | ||
Ascending = -1, | ||
Same = 0, | ||
Descending = 1, | ||
} | ||
|
||
impl Default for NSComparisonResult { | ||
fn default() -> Self { | ||
Self::Same | ||
} | ||
} | ||
|
||
unsafe impl Encode for NSComparisonResult { | ||
const ENCODING: Encoding<'static> = isize::ENCODING; | ||
} | ||
|
||
impl NSComparisonResult { | ||
pub fn from_ordering(order: Ordering) -> NSComparisonResult { | ||
unsafe impl RefEncode for NSComparisonResult { | ||
const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&Self::ENCODING); | ||
} | ||
|
||
impl From<Ordering> for NSComparisonResult { | ||
fn from(order: Ordering) -> Self { | ||
match order { | ||
Ordering::Less => NSComparisonResult::Ascending, | ||
Ordering::Equal => NSComparisonResult::Same, | ||
Ordering::Greater => NSComparisonResult::Descending, | ||
Ordering::Less => Self::Ascending, | ||
Ordering::Equal => Self::Same, | ||
Ordering::Greater => Self::Descending, | ||
} | ||
} | ||
} | ||
|
||
pub fn as_ordering(&self) -> Ordering { | ||
match *self { | ||
NSComparisonResult::Ascending => Ordering::Less, | ||
NSComparisonResult::Same => Ordering::Equal, | ||
NSComparisonResult::Descending => Ordering::Greater, | ||
impl From<NSComparisonResult> for Ordering { | ||
fn from(comparison_result: NSComparisonResult) -> Self { | ||
match comparison_result { | ||
NSComparisonResult::Ascending => Self::Less, | ||
NSComparisonResult::Same => Self::Equal, | ||
NSComparisonResult::Descending => Self::Greater, | ||
} | ||
} | ||
} |