-
Notifications
You must be signed in to change notification settings - Fork 18
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
10 changed files
with
126 additions
and
109 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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//! Vendor the ['equivalent'](https://crates.io/crates/equivalent) crate in order to avoid any conflicts. | ||
use std::{borrow::Borrow, cmp::Ordering}; | ||
|
||
/// Key equivalence trait. | ||
pub trait Equivalent<K: ?Sized> { | ||
/// Compare self to `key` and return `true` if they are equal. | ||
fn equivalent(&self, key: &K) -> bool; | ||
} | ||
|
||
impl<Q: ?Sized, K: ?Sized> Equivalent<K> for Q | ||
where | ||
Q: Eq, | ||
K: Borrow<Q>, | ||
{ | ||
#[inline] | ||
fn equivalent(&self, key: &K) -> bool { | ||
PartialEq::eq(self, key.borrow()) | ||
} | ||
} | ||
|
||
/// Key ordering trait. | ||
pub trait Comparable<K: ?Sized>: Equivalent<K> { | ||
/// Compare self to `key` and return their ordering. | ||
fn compare(&self, key: &K) -> Ordering; | ||
} | ||
|
||
impl<Q: ?Sized, K: ?Sized> Comparable<K> for Q | ||
where | ||
Q: Ord, | ||
K: Borrow<Q>, | ||
{ | ||
#[inline] | ||
fn compare(&self, key: &K) -> Ordering { | ||
Ord::cmp(self, key.borrow()) | ||
} | ||
} |
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
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
Oops, something went wrong.