Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SliceIndex for ByteStr #138381

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thaliaarchi
Copy link
Contributor

@thaliaarchi thaliaarchi commented Mar 12, 2025

Implement Index and IndexMut for ByteStr in terms of SliceIndex. Implement it for the same types that &[u8] supports (a superset of those supported for &str, which does not have usize and ops::IndexRange).

At the same time, move compare and index traits to a separate file in the bstr module, to give it more space to grow as more functionality is added (e.g., iterators and string-like ops). Order the items in bstr/traits.rs similarly to str/traits.rs.

cc @joshtriplett

ByteStr/ByteString tracking issue: #134915

This parallels the layout of `core::str`.
@rustbot
Copy link
Collaborator

rustbot commented Mar 12, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 12, 2025
@rust-log-analyzer

This comment has been minimized.

@joshtriplett
Copy link
Member

LGTM, once it passes CI.

@thaliaarchi
Copy link
Contributor Author

thaliaarchi commented Mar 12, 2025

I needed to update snapshots for UI tests. Unfortunately, I think the diagnostics are now slightly worse. If these tests are on stable, they shouldn't be shown ByteStr.

I think it's also related to these impls being transitive: the index type implements SliceIndex<_>, then slice types implement Index for all types which implement SliceIndex<Self>. It would be better for suggestions to filter the index types to just those who implement SliceIndex<_> for the container.

@thaliaarchi
Copy link
Contributor Author

@joshtriplett CI passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants