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

Add ArrayString::from_utf8 #251

Open
Aegrithas opened this issue Oct 13, 2023 · 0 comments
Open

Add ArrayString::from_utf8 #251

Aegrithas opened this issue Oct 13, 2023 · 0 comments

Comments

@Aegrithas
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant