-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Currently, OsStr
provides a very rudimentary len
function, which is used to determine capacity requirements for OsString
. I feel like this is grounds enough to allow slicing over these strings.
The main use case for this would be storing multiple strings in the same OsStr
buffer, then slicing them out based upon their lengths. This is particularly useful if you have a struct which requires multiple OsStr
s but don't want to allocate a new box for each one, and know the lengths of all of them.
This is particularly useful because while CStr
and str
both have ways of accessing the bytes that make up the string, OsStr
doesn't.
Obviously, slicing wouldn't make sense on CStr
, because you can't just inject nuls into the middle of the string. However, it could also benefit from similar capacity-based functions on OsString
alongside some kind of push
method. Right now, you have to convert the string to a vec, mess with the string, then re-convert it into a CString
to do any of this stuff.
While these types are not as widely used as String
, it'd be nice if they were more consistent with String
's API.