2 ms·
> Creating a non-UTF8 rust string is UB. So how does rust deal with filenames under Linux? Use somethinge other than strings?
by account42 7y ago
> Creating a non-UTF8 rust string is UB.
So how does rust deal with filenames under Linux? Use somethinge other than strings?
- masklinn 7y agoYes: https://doc.rust-lang.org/std/ffi/struct.OsString.html https://doc.rust-lang.org/std/ffi/struct.OsString.html This is also used to deal with filenames on Windows, as they're a different flavour of "not unicode", IIRC that's the original use case for WTF8. It also has a separate pseudo-string type to deal with C strings: https://doc.rust-lang.org/std/ffi/struct.CString.html https://doc.rust-lang.org/std/ffi/struct.CString.html
- loonyphoenix 7y agoYep. Rust has a PathBuf[1] type for dealing with paths in a platform-native manner. You can convert it to a Rust string type, but it's a conversion that can fail[2] or may be lossy[3]. [1] https://doc.rust-lang.org/std/path/struct.PathBuf.html https://doc.rust-lang.org/std/path/struct.PathBuf.html [2] https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.to_str https://doc.rust-lang.org/std/path/struct.PathBuf.html#metho... [3] https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.to_string_lossy https://doc.rust-lang.org/std/path/struct.PathBuf.html#metho...
- TheCoelacanth 7y agoYes, this is what OsStr/OsString[1] are for. [1] https://doc.rust-lang.org/std/ffi/struct.OsString.html https://doc.rust-lang.org/std/ffi/struct.OsString.html
- deleted 7y ago[deleted]