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

Move Utf8Chunks::new to be inherent on [u8] #190

Closed
dylni opened this issue Mar 12, 2023 · 1 comment
Closed

Move Utf8Chunks::new to be inherent on [u8] #190

dylni opened this issue Mar 12, 2023 · 1 comment
Labels
ACP-accepted API Change Proposal is accepted (seconded with no objections) api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api

Comments

@dylni
Copy link

dylni commented Mar 12, 2023

Proposal

Problem statement

Utf8Chunks::new requires importing Utf8Chunks. Adding this method on [u8] would allow it to be used without an import.

This API is unstable, so this is not a breaking change.

Motivation, use-cases

This is similar to other methods treating [u8] as a byte string, such as <[u8]>::is_ascii.

Example

Code using Utf8Chunks::new:

use std::str::Utf8Chunks;

for chunk in Utf8Chunks::new(string) {
    let valid = chunk.valid();
    let invalid = chunk.invalid();
    // formatting for `valid` and `invalid`
}

Code using <[u8]>::utf8_chunks:

for chunk in string.utf8_chunks() {
    let valid = chunk.valid();
    let invalid = chunk.invalid();
    // formatting for `valid` and `invalid`
}

Solution sketches

Current signature:

impl<'a> Utf8Chunks<'a> {
    fn new(bytes: &'a [u8]) -> Self;
}

Proposed signature:

impl [u8] {
    fn utf8_chunks(&self) -> Utf8Chunks<'_>;
}

Links and related work

What happens now?

This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.

@dylni dylni added api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api labels Mar 12, 2023
@dtolnay dtolnay added the ACP-accepted API Change Proposal is accepted (seconded with no objections) label Apr 11, 2024
@dtolnay dtolnay closed this as completed Apr 11, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 15, 2024
Stabilize `Utf8Chunks`

Pending FCP in rust-lang#99543.

This PR includes the proposed modification in rust-lang/libs-team#190 as agreed in rust-lang#99543 (comment).
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 26, 2024
Stabilize `Utf8Chunks`

Pending FCP in rust-lang#99543.

This PR includes the proposed modification in rust-lang/libs-team#190 as agreed in rust-lang#99543 (comment).
RalfJung pushed a commit to RalfJung/miri that referenced this issue Apr 27, 2024
Stabilize `Utf8Chunks`

Pending FCP in rust-lang/rust#99543.

This PR includes the proposed modification in rust-lang/libs-team#190 as agreed in rust-lang/rust#99543 (comment).
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
Stabilize `Utf8Chunks`

Pending FCP in rust-lang/rust#99543.

This PR includes the proposed modification in rust-lang/libs-team#190 as agreed in rust-lang/rust#99543 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ACP-accepted API Change Proposal is accepted (seconded with no objections) api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api
Projects
None yet
Development

No branches or pull requests

2 participants