4 ms·
I've went through the rust book, unfortunately I learn better through actually trying to do things while looking at the API reference. And the rust documentatio
by mook 10y ago
I've went through the rust book, unfortunately I learn better through actually trying to do things while looking at the API reference. And the rust documentation is frustrating for that, simply because everything is expanded by default and there's no concise list of functions available.
(In my case, I wanted to print out the name of the executable. Having to convert OsStr to something I can print, I understand - the filesystem encoding can be different from the console encoding. But it took longer than it should to find a path between the two.)
- Tarean 10y agoI mean, pressing the button to collapse the documentation isn't very hard http://i.imgur.com/rcI3JG5.jpg http://i.imgur.com/rcI3JG5.jpg I never had to print an osstr yet but it seems fairly straightforward when looking at the docs? There are three obvious functions one could use, each for different use cases: https://doc.rust-lang.org/std/ffi/struct.OsString.html https://doc.rust-lang.org/std/ffi/struct.OsString.html os_string.to_str() // returns Option<String> os_string.to_string_lossy() // returns Cow<String>, replacing illegal characters os_string.into_string() // returns Result<String, OsString> - String if the data is valid, stays OsString for error handling otherwise