Skip to content

Add ArrayString::from_utf8 #251

Description

@Aegrithas

I have a use case that requires me to construct an ArrayString<CAP> from a UTF-8 ArrayVec<u8, CAP>. For Vec<u8> to String, I would use String::from_utf8, but the closest equivalent is ArrayString::from_byte_string, which won't work if the ArrayVec is not full. Therefore, I'd like to request a method such as:

impl<const CAP: usize> ArrayString<CAP> {

  pub fn from_utf8(vec: ArrayVec<u8, CAP>) -> Result<ArrayString<CAP>, FromUtf8Error<CAP>>;

}

This specific design entails adding a struct FromUtf8Error<const CAP: usize>, which would mimic std::string::FromUtf8Error; with that said, I'm not fussed about the specifics as long as I can (fallibly) get an ArrayString<CAP> from an ArrayVec<u8, CAP>.

Also, I have a workaround, so I'm not looking for solutions; it's just less elegant (and std-like) than I'd like.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions