flexstr
flexstr copied to clipboard
Byte and OsStr variants?
I'm still undecided on what type I'll use in clap (Cow<'static, T>
or a more specialized crate) but I'll be needing both str
and OsStr
support.
On reddit, it sounded like there is also interest in byte strings. Hopefully byte strings and OsStr
will be merged soon but unsure if/when that'll happen.
I'm playing with this in a branch right now. I definitely want to add this. I'm just trying to work out the design. Generics are starting to look nasty and are impossible to hide w/o a newtype and either reimplementing or 100% macros. Still trying to figure out the best path forward. Let me know if you have ideas.
I should probably add that if you are willing to use FlexStr
in Clap
... let's just say I'm very interested to hear what you need :-)
BStr
, [u8]
and CStr
should be doable.
I'm not seeing a way to do OsStr
unless you have some ideas I'm not thinking of. The problem is that the type is considered opaque, so while I could easily onboard the string as [u8]
today and then transmute
to deref
it - this would be undefined behavior so I'd likely feel the need to put it behind an unsafe_osstr
feature flag... if I did it at all, which would scare everyone away from using it. For str
we are lucky to have from_utf8_unchecked
, but no corresponding function exists for OsStr
that I can tell. Even the os_str_bytes
lib takes the safe way out and uses stdlib, fine for conversion, but not for realtime deref
from [u8]
to OsStr
.
For working with OsStr, clap relies on https://docs.rs/os_str_bytes/latest/os_str_bytes/
Even the
os_str_bytes
lib takes the safe way out and uses stdlib, fine for conversion, but not for realtime deref from[u8]
toOsStr
Great little crate, not much use for what I need after looking at it last night. The only hold up is how to do inline strings. I need to convert from a &[u8]
to a &OsStr
as a zero-cost conversion. Best I can tell, there is no way to do it. If I transmute, it will be UB. I'm reimplementing the core of FlexStr
to do all this, so I may just skip inline strings for OsStr
- would be a bummer but at least some support.