Closed
Description
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
- Tracking issue: Tracking Issue for
utf8_chunks
rust#99543 - Proposal: Expose
Utf8LossyChunksIter
#54 - Implementation: Expose
Utf8Lossy
asUtf8Chunks
rust#99544
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.