Skip to content

Implement PartialEq<[u8]> for QByteArray and PartialEq<str> for QString#1446

Open
jnbooth wants to merge 3 commits into
KDAB:mainfrom
jnbooth:more-partial-eq
Open

Implement PartialEq<[u8]> for QByteArray and PartialEq<str> for QString#1446
jnbooth wants to merge 3 commits into
KDAB:mainfrom
jnbooth:more-partial-eq

Conversation

@jnbooth

@jnbooth jnbooth commented May 6, 2026

Copy link
Copy Markdown
Contributor

In Qt, you can test equality for QByteArrays and QStrings against raw data without needing to allocate memory, e.g. QStringLiteral("test") == "test". This PR makes it possible to do the same in Rust by implementing PartialEq for the corresponding types.

@codecov

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (061eaad) to head (9cc12c2).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1446   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           75        75           
  Lines        13455     13455           
=========================================
  Hits         13455     13455           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +250 to +254
impl PartialEq<str> for QString {
fn eq(&self, other: &str) -> bool {
self.as_slice().iter().copied().eq(other.encode_utf16())
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm wonder if we want this one, as most of the time the API ends up being explicit about when there is a copy or conversion to/from utf16 or runtime cost ? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants