Skip to content

Consider adding starts_with method for OsStr #49816

Closed
@Kixunil

Description

When parsing arguments, one often wants to know whether the argument starts with "--" or "-". At the same time, args_os() is more robust approach because it allows specifying all paths OS allows.

However, since there's no starts_with method, this is impossible on Windows and requires OsStrExt trait with converting to byte slice on Unix. An imperfect workaround would be attempting to convert to &str and assume false if conversion fails (hoping argument names are sane - not containing non-ASCII chars).

Similarly, ends_with could be added.

I hope this doesn't need RFC, since it should be a very small and easy change.

Another thing that comes to my mind: arguments like --foo=bar can't be parsed - this requires slicing too.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions