diff --git a/src/string.rs b/src/string.rs index 734cd81..636c725 100644 --- a/src/string.rs +++ b/src/string.rs @@ -164,19 +164,25 @@ where } } -impl PartialEq 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 { + 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(&self, state: &mut H) { @@ -244,6 +250,8 @@ where } } +impl Eq for BorrowedStr<'_> {} + impl PartialOrd for BorrowedStr<'_> where T: AsRef, @@ -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 PartialOrd 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>; diff --git a/tests/conversion.rs b/tests/conversion.rs index 5ca9982..d0e7a07 100644 --- a/tests/conversion.rs +++ b/tests/conversion.rs @@ -33,7 +33,7 @@ fn test_string_into_lua() -> Result<()> { // Direct conversion let s = lua.create_string("hello, world!")?; let s2 = (&s).into_lua(&lua)?; - assert_eq!(s, s2.as_string().unwrap()); + assert_eq!(s, *s2.as_string().unwrap()); // Push into stack let table = lua.create_table()?;