Skip to content

Bringing OsStr and CStr up to par with str #1876

@clarfonthey

Description

@clarfonthey

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 OsStrs 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions