4 ms·
I feel you two are talking past each other a bit. > Stepping back: the problem you're trying to solve is literally impossible to solve at compile time. This i
by spoiler 2y ago
I feel you two are talking past each other a bit.
> Stepping back: the problem you're trying to solve is literally impossible to solve at compile time.
This is not being solved at compile time. OsString/OsStr (and PathBuf/Path) are basically there for ergonomics _and_ safety. They're not just used for filesystem paths either, but for other things too.
All the checks happen at runtime time (but only the checks relevant for the target platform, since it's different implementations per platform) when converting between String and OsString.
For path manipulation and filename encoding quirks (I don't know much about those) I think some of it is done in-memory, but a lot of it happens when you access the disk, that's true.
However you can still isolate those checks early and pass file references, or do a preflight check.
You can do this in others languages too, but Rust surfaces the potential issues nicely with Result in combination with other type system features, and makes the handling of those cases more ergonomic than most things I've worked with