Consider adding starts_with method for OsStr · Issue #49816 · rust-lang/rust (original) (raw)

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.