OsStr: compare prefix · Issue #40300 · rust-lang/rust (original) (raw)

@nagisa

OsStr could implement a way to compare against prefix &str (as it does not implement iterators over its data), similarly to how it implements comparison against &str.

Currently you need to go out of your way to convert to bytes. as_str is not suitable, as following case shows:

let x = /* OsStr with invalid utf8 */;
x.as_str().map(|x| x.starts_with("-")).unwrap_or(false); // false even if only the first byte really matters