mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
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:
parent
5d77b36f24
commit
ea33f9470b
1 changed files with 26 additions and 0 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue