fix: Ensure partial eq is symetric

This commit is contained in:
Ed Page 2022-08-19 16:44:48 -05:00
parent d04ecd41f3
commit 6de312f50a
3 changed files with 106 additions and 1 deletions

View file

@ -99,6 +99,12 @@ impl PartialEq<str> for Id {
PartialEq::eq(self.as_str(), other)
}
}
impl PartialEq<Id> for str {
#[inline]
fn eq(&self, other: &Id) -> bool {
PartialEq::eq(self, other.as_str())
}
}
impl PartialEq<&'_ str> for Id {
#[inline]
@ -106,6 +112,12 @@ impl PartialEq<&'_ str> for Id {
PartialEq::eq(self.as_str(), *other)
}
}
impl PartialEq<Id> for &'_ str {
#[inline]
fn eq(&self, other: &Id) -> bool {
PartialEq::eq(*self, other.as_str())
}
}
impl PartialEq<Str> for Id {
#[inline]
@ -113,6 +125,12 @@ impl PartialEq<Str> for Id {
PartialEq::eq(self.as_str(), other.as_str())
}
}
impl PartialEq<Id> for Str {
#[inline]
fn eq(&self, other: &Id) -> bool {
PartialEq::eq(self.as_str(), other.as_str())
}
}
impl PartialEq<std::string::String> for Id {
#[inline]
@ -120,3 +138,9 @@ impl PartialEq<std::string::String> for Id {
PartialEq::eq(self.as_str(), other.as_str())
}
}
impl PartialEq<Id> for std::string::String {
#[inline]
fn eq(&self, other: &Id) -> bool {
PartialEq::eq(other, self)
}
}

View file

@ -149,6 +149,12 @@ impl PartialEq<str> for OsStr {
PartialEq::eq(self.as_os_str(), other)
}
}
impl PartialEq<OsStr> for str {
#[inline]
fn eq(&self, other: &OsStr) -> bool {
PartialEq::eq(self, other.as_os_str())
}
}
impl PartialEq<&'_ str> for OsStr {
#[inline]
@ -156,13 +162,25 @@ impl PartialEq<&'_ str> for OsStr {
PartialEq::eq(self.as_os_str(), *other)
}
}
impl PartialEq<OsStr> for &'_ str {
#[inline]
fn eq(&self, other: &OsStr) -> bool {
PartialEq::eq(*self, other.as_os_str())
}
}
impl<'s> PartialEq<&'s std::ffi::OsStr> for OsStr {
impl PartialEq<&'_ std::ffi::OsStr> for OsStr {
#[inline]
fn eq(&self, other: &&std::ffi::OsStr) -> bool {
PartialEq::eq(self.as_os_str(), *other)
}
}
impl PartialEq<OsStr> for &'_ std::ffi::OsStr {
#[inline]
fn eq(&self, other: &OsStr) -> bool {
PartialEq::eq(*self, other.as_os_str())
}
}
impl PartialEq<std::string::String> for OsStr {
#[inline]
@ -170,6 +188,12 @@ impl PartialEq<std::string::String> for OsStr {
PartialEq::eq(self.as_os_str(), other.as_str())
}
}
impl PartialEq<OsStr> for std::string::String {
#[inline]
fn eq(&self, other: &OsStr) -> bool {
PartialEq::eq(self.as_str(), other.as_os_str())
}
}
impl PartialEq<std::ffi::OsString> for OsStr {
#[inline]
@ -177,6 +201,12 @@ impl PartialEq<std::ffi::OsString> for OsStr {
PartialEq::eq(self.as_os_str(), other.as_os_str())
}
}
impl PartialEq<OsStr> for std::ffi::OsString {
#[inline]
fn eq(&self, other: &OsStr) -> bool {
PartialEq::eq(self.as_os_str(), other.as_os_str())
}
}
#[derive(Clone)]
enum Inner {

View file

@ -33,6 +33,13 @@ impl Str {
}
}
impl Default for &'_ Str {
fn default() -> Self {
static DEFAULT: Str = Str::from_static_ref("");
&DEFAULT
}
}
impl From<&'_ Str> for Str {
fn from(id: &'_ Str) -> Self {
id.clone()
@ -127,6 +134,12 @@ impl PartialEq<str> for Str {
PartialEq::eq(self.as_str(), other)
}
}
impl PartialEq<Str> for str {
#[inline]
fn eq(&self, other: &Str) -> bool {
PartialEq::eq(self, other.as_str())
}
}
impl PartialEq<&'_ str> for Str {
#[inline]
@ -134,6 +147,38 @@ impl PartialEq<&'_ str> for Str {
PartialEq::eq(self.as_str(), *other)
}
}
impl PartialEq<Str> for &'_ str {
#[inline]
fn eq(&self, other: &Str) -> bool {
PartialEq::eq(*self, other.as_str())
}
}
impl PartialEq<std::ffi::OsStr> for Str {
#[inline]
fn eq(&self, other: &std::ffi::OsStr) -> bool {
PartialEq::eq(self.as_str(), other)
}
}
impl PartialEq<Str> for std::ffi::OsStr {
#[inline]
fn eq(&self, other: &Str) -> bool {
PartialEq::eq(self, other.as_str())
}
}
impl PartialEq<&'_ std::ffi::OsStr> for Str {
#[inline]
fn eq(&self, other: &&std::ffi::OsStr) -> bool {
PartialEq::eq(self.as_str(), *other)
}
}
impl PartialEq<Str> for &'_ std::ffi::OsStr {
#[inline]
fn eq(&self, other: &Str) -> bool {
PartialEq::eq(*self, other.as_str())
}
}
impl PartialEq<std::string::String> for Str {
#[inline]
@ -141,6 +186,12 @@ impl PartialEq<std::string::String> for Str {
PartialEq::eq(self.as_str(), other.as_str())
}
}
impl PartialEq<Str> for std::string::String {
#[inline]
fn eq(&self, other: &Str) -> bool {
PartialEq::eq(self.as_str(), other.as_str())
}
}
#[derive(Clone)]
pub(crate) enum Inner {