-
Notifications
You must be signed in to change notification settings - Fork 5
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
KBString for byte strings? #37
Comments
Are you looking for just a compact If you are fine with |
This enhancement would be very relevant for |
I ended up doing something like this: /// A reference container to encapsulate a tightly packed and typically unallocated byte value that isn't necessarily UTF8 encoded.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
pub struct ValueRef<'a>(KStringRef<'a>);
/// Conversions
impl<'a> ValueRef<'a> {
/// Keep `input` as our value.
pub fn from_bytes(input: &'a [u8]) -> Self {
Self(KStringRef::from_ref(
// SAFETY: our API makes accessing that value as `str` impossible, so illformed UTF8 is never exposed as such.
#[allow(unsafe_code)]
unsafe {
std::str::from_utf8_unchecked(input)
},
))
}
/// Access this value as byte string.
pub fn as_bstr(&self) -> &BStr {
self.0.as_bytes().as_bstr()
}
} I am writing this here just to assure myself that |
I'd love to have a version of
KString
that can hold arbitrary bytes, rather than UTF-8. I currently use BString, but I'd love to have the compact string optimization of KString.The text was updated successfully, but these errors were encountered: