fix: impl PartialEq<str> for CompactStr (#4352)

I need this for another PR that I'm working on, but I think adding this just makes sense.
This commit is contained in:
DonIsaac 2024-07-19 16:39:10 +00:00
parent 5d77b36f24
commit ea33f9470b

View file

@ -297,6 +297,18 @@ impl PartialEq<CompactStr> for &str {
}
}
impl PartialEq<CompactStr> for str {
fn eq(&self, other: &CompactStr) -> bool {
self == other.as_str()
}
}
impl PartialEq<str> for CompactStr {
fn eq(&self, other: &str) -> bool {
self.as_str() == other
}
}
impl Index<Span> for CompactStr {
type Output = str;
@ -332,3 +344,17 @@ impl Serialize for CompactStr {
serializer.serialize_str(self.as_str())
}
}
#[cfg(test)]
mod test {
use super::CompactStr;
#[test]
fn test_compactstr_eq() {
let foo = CompactStr::new("foo");
assert_eq!(foo, "foo");
assert_eq!(&foo, "foo");
assert_eq!("foo", foo);
assert_eq!("foo", &foo);
}
}