Skip to content

Commit

Permalink
Rollup merge of rust-lang#91697 - dtolnay:lossyfromstr, r=Mark-Simula…
Browse files Browse the repository at this point in the history
…crum

Delete Utf8Lossy::from_str

This whole type is marked as being for str internals only, but this constructor is never used by str internals. If you had a &str already and wanted to lossy display it or iterate its lossy utf8 chunks, you would simply not use Utf8Lossy because the whole &str is known to be one contiguous valid utf8 chunk.

If code really does need to obtain a value of type &Utf8Lossy somewhere, and has only a &str, `Utf8Lossy::from_bytes(s.as_bytes())` remains available. As currently implemented, there is no performance penalty relative to `from_str` i.e. the Utf8Lossy does not "remember" that it was constructed using `from_str` to bypass later utf8 decoding.
  • Loading branch information
matthiaskrgr committed Dec 10, 2021
2 parents 51fb3cb + 4b0a9c9 commit 5934aa8
Showing 1 changed file with 0 additions and 5 deletions.
5 changes: 0 additions & 5 deletions library/core/src/str/lossy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ pub struct Utf8Lossy {
}

impl Utf8Lossy {
#[must_use]
pub fn from_str(s: &str) -> &Utf8Lossy {
Utf8Lossy::from_bytes(s.as_bytes())
}

#[must_use]
pub fn from_bytes(bytes: &[u8]) -> &Utf8Lossy {
// SAFETY: Both use the same memory layout, and UTF-8 correctness isn't required.
Expand Down

0 comments on commit 5934aa8

Please sign in to comment.