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

Add substring API for OsStr #118484

Merged
merged 1 commit into from
Dec 2, 2023
Merged

Add substring API for OsStr #118484

merged 1 commit into from
Dec 2, 2023

Conversation

blyxxyz
Copy link
Contributor

@blyxxyz blyxxyz commented Nov 30, 2023

This adds a method for taking a substring of an OsStr, which in combination with OsStr::as_encoded_bytes() makes it possible to implement most string operations in safe code.

API:

impl OsStr {
    pub fn slice_encoded_bytes<R: ops::RangeBounds<usize>>(&self, range: R) -> &Self;
}

Motivation, examples and research at rust-lang/libs-team#306.

Tracking issue: #118485

cc @epage
r? libs-api

@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 Nov 30, 2023
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@blyxxyz blyxxyz force-pushed the os-str-slice branch 2 times, most recently from 6e11da1 to f545e89 Compare November 30, 2023 18:33
@epage
Copy link
Contributor

epage commented Nov 30, 2023

Open question: Currently this enforces the same requirements on all platforms, but on Unix (and some other platforms) the internal encoding of OsStr is already fully specified to be arbitrary bytes by means of the OsStrExt trait. Should we:

Should we defer this discussion to the tracking issue?

@rust-log-analyzer

This comment has been minimized.

@BurntSushi
Copy link
Member

LGTM. r=me after adding some messages to the asserts. Maybe copy what we do for str slice panicking?

@blyxxyz
Copy link
Contributor Author

blyxxyz commented Dec 2, 2023

str gives messages like byte index 1 is not a char boundary; it is inside '∞' (bytes 0..3) of "∞". It's difficult to be that helpful when we don't have any known-valid context, so I made it byte index {index} is not an OsStr boundary.

I've started work on an implementation with platform logic but maybe that could become a followup PR.

@BurntSushi
Copy link
Member

I buy it. @bors r+

@bors
Copy link
Contributor

bors commented Dec 2, 2023

📌 Commit 729851e has been approved by BurntSushi

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 2, 2023
@bors
Copy link
Contributor

bors commented Dec 2, 2023

⌛ Testing commit 729851e with merge d5fab33...

@bors
Copy link
Contributor

bors commented Dec 2, 2023

☀️ Test successful - checks-actions
Approved by: BurntSushi
Pushing d5fab33 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 2, 2023
@bors bors merged commit d5fab33 into rust-lang:master Dec 2, 2023
11 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Dec 2, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d5fab33): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.7% [-3.9%, -3.6%] 2
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 672.666s -> 671.733s (-0.14%)
Artifact size: 313.96 MiB -> 313.93 MiB (-0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

8 participants