Paths may be arbitrary sequences of bytes, so we cannot guarantee that they are utf8 or even convertible to utf8 and back. However, we do want to be able to convert the path to utf8, and vice versa.
LexicalPath
currently deals with manipulating paths and getting their parts. Do we roll this intoPath
?Core::Directory
deals with iteration, stat and open. Do we roll this intoPath
?Core::DeprecatedFile
has methods for other filesystem checks and operations. Do we roll this intoPath
?Core::StandardPaths
provides getters for the home directory path, and friends. Do we roll this intoPath
?
Rust has a Path
class for a path, allowing you to access its components and query if it's a directory etc; and PathBuf
class as a kind of StringBuilder thing?
Python distinguishes between "pure" and "concrete" paths. Pure paths are only hypothetical and don't include any functionality requiring filesystem access. Paths extends them with filesystem functionality.
Python has a couple of neat helper functions:
relative_to(other)
: produces a path that'sthis/other
, normalised.with_name(name)
: produces a path that isthis
, but with the filename changed.with_stem(stem)
andwith_suffix(suffix)
: produce paths that arethis
, but with the file basename or extension changed.expanduser()
: Replaces~/
with the path to the user's directory.
We also have a Jakt Path. It's basically a LexicalPath? But produces the components on demand instead of storing a dozen Strings inside.
POSIX has some things to say about paths.
Windows has some... unfortunate complications with paths:
\
as a separator. (Not that big a deal probably.)- Case insensitivity
- Drive letters
\foo
is a rooted path, but not an absolute one. (Do we care about this distinction?)
So, rough idea:
- Construct from
StringView
orSpan<StringView>
StringView raw_path()
String to_string()
- Return a new path:
- relative_to(Path)
- with_filename(StringView)
- with_file_extension(StringView)
- with_file_basename(StringView)
- Static
Path cwd()
- All the getters from
Core::StandardPaths
- absolutize(StringView)