Skip to content

Consider adding starts_with method for OsStr #49816

Closed

Description

@Kixunil

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.

Activity

  1. clarfonthey commented on Apr 9, 2018

    @clarfonthey
    Contributor

    This is a duplicate of #49802; an RFC was proposed for this and it just has to be implemented. :)

  2. Kixunil commented on Apr 9, 2018

    @Kixunil
    ContributorAuthor

    Weird that I didn't find it using Google. Thanks!

    I'm closing in favor of that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

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