-
Notifications
You must be signed in to change notification settings - Fork 144
Open
Description
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.
Zoybean
Metadata
Metadata
Assignees
Labels
No labels