Skip to content

Request: Lossy way to move Vec<u8> into a String #64727

Closed

Description

If you have a Vec<u8> of utf8 data there's three ways to get a String:

  • from_utf8(vec: Vec<u8>) -> Result<String, FromUtf8Error>
  • from_utf8_lossy(v: &'a [u8]) -> Cow<'a, str>
  • unsafe fn from_utf8_unchecked(bytes: Vec<u8>) -> String

There doesn't appear to be any way to hand over the existing Vec<u8> and have any necessary character changes into be done in place. The std::string::FromUtf8Error type doesn't, for example, have a way to just do a lossy in-place conversion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions