Module path

Source
Available on Linux only.
Expand description

Types for representing valid file system paths. OwnedPath and Path are available as owned and slice representations, respectively.

This module provides types which represent valid (although not necessarily existent) paths for an operating system / file system. (Currently only for Linux, like the rest of fs).

§Approach

Paths are represented by one of two types, using the type-state pattern:

  • OwnedPath: An owned mutable string representing a valid path.
  • Path: A slice representing a valid path. (Note: The slice itself is valid, and isn’t just a slice of a valid OwnedPath.)

Each of these types is accompanied by a state, representing whether the path is absolute (Abs) or relative (Rel). Both of these states are represented as zero-variant enums, so they can’t be instantiated.

For most file operations, an Abs path will be required, meaning that relative paths need to be resolved first.

§Validity

Both path types uphold the following invariants to ensure that the contained OsString is valid:

  • The string starts with /.
  • The string contains no repeated / characters or occurrences of /./.
  • The string contains no trailing /.
  • The string contains no \0.

Although these invariants are relatively strict, constructing an OwnedPath from an OsStr or str is infallible because it sanitizes any invalid string provided. On the other hand, constructing a Path from another slice type can fail and may do so relatively often, because it won’t mutate the original value, only verify that it is already valid.

§Ensuring Existence

A path being valid doesn’t ensure that it exists. TODO

Structs§

Ancestors
Components
DisplayDotSlash
DisplayFull
DisplayHome
DisplayNoLead
DisplayPath
DisplaySlash
OwnedPath
Path

Enums§

Abs
DispatchedPath
An OwnedPath with a statically dispatched state. TODO
PathError
PathOrMetadataError
PathParseError
Rel

Traits§

PathState