Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions crates/oxc_span/src/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}