[Pre-RFC] Additional path handling utilities

It might be worth taking a look at what Boost.Filesystem does here:

https://www.boost.org/doc/libs/1_68_0/libs/filesystem/doc/reference.html#path-decomposition-table

1 Like

This method returns the ā€œheadā€ of a path; that is, the Prefix and RootDir components (if any). This is useful for implementing ā€œadjoinmentā€ logic (if you want to implement your own alternative to canonicalize() ) and could also be useful for Windows programs want to know whether two paths are on the same drive.

In Python's pathlib, this is called .anchor.

There is a suggestion in the API Guidelines to offer unchecked versions of functions that are unsafe. There is some question about invariant-safety vs memory-safety so I've opened rust-lang-nursery/api-guidelines#179

That's not the case: PathBuf is a newtype around OsString, which has different guarantees than String.

Due to the &str (or &OsStr at least) to Path and vice-versa AsRef conversions, itā€™s impossible to have Path be a NULL-terminated array of OsStr in platforms that use such representation.

This also applies to PathBuf.

AsRef = type-punned.

fs::normalize on Windows needs to be implemented using GetFullPathNameW. Doing anything else is liable to get things wrong in corner cases.

Also just a reminder that people should read https://googleprojectzero.blogspot.com/2016/02/the-definitive-guide-on-win32-to-nt.html

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.