impl Eq/Ord for Lua String

This commit is contained in:
Alex Orlenko
2024-10-01 23:20:19 +01:00
parent 4b8c26e682
commit ad9bc36764
2 changed files with 28 additions and 6 deletions
+27 -5
View File
@@ -164,19 +164,25 @@ where
}
}
impl PartialEq<String> for String {
impl PartialEq for String {
fn eq(&self, other: &String) -> bool {
self.as_bytes() == other.as_bytes()
}
}
impl PartialEq<&String> for String {
fn eq(&self, other: &&String) -> bool {
self.as_bytes() == other.as_bytes()
impl Eq for String {}
impl PartialOrd for String {
fn partial_cmp(&self, other: &String) -> Option<cmp::Ordering> {
self.as_bytes().partial_cmp(&other.as_bytes())
}
}
impl Eq for String {}
impl Ord for String {
fn cmp(&self, other: &String) -> cmp::Ordering {
self.as_bytes().cmp(&other.as_bytes())
}
}
impl Hash for String {
fn hash<H: Hasher>(&self, state: &mut H) {
@@ -244,6 +250,8 @@ where
}
}
impl Eq for BorrowedStr<'_> {}
impl<T> PartialOrd<T> for BorrowedStr<'_>
where
T: AsRef<str>,
@@ -253,6 +261,12 @@ where
}
}
impl Ord for BorrowedStr<'_> {
fn cmp(&self, other: &Self) -> cmp::Ordering {
self.0.cmp(other.0)
}
}
/// A borrowed byte slice (`&[u8]`) that holds a strong reference to the Lua state.
pub struct BorrowedBytes<'a>(&'a [u8], #[allow(unused)] Lua);
@@ -294,6 +308,8 @@ where
}
}
impl Eq for BorrowedBytes<'_> {}
impl<T> PartialOrd<T> for BorrowedBytes<'_>
where
T: AsRef<[u8]>,
@@ -303,6 +319,12 @@ where
}
}
impl Ord for BorrowedBytes<'_> {
fn cmp(&self, other: &Self) -> cmp::Ordering {
self.0.cmp(other.0)
}
}
impl<'a> IntoIterator for BorrowedBytes<'a> {
type Item = &'a u8;
type IntoIter = slice::Iter<'a, u8>;