Path v0.1.0
Installation
Add Path to the [Dependencies] table of your package's Rux.toml:
[Dependencies]
Path = { Namespace = "Rux", Version = "0.1.0" }
Standard packages are declared by hand: the registry does not serve them, so rux add Rux/Path cannot add them.
Dependencies
Guide
What it provides
OsStringandOsStringView— text as the operating system actually stores it: arbitrary bytes on the Unix systems, arbitrary UTF-16 code units on Windows, unpaired surrogates included. Lossless by construction: whatever name the system hands over survives the round trip, whether or not it is valid text. Conversion from UTF-8 always succeeds; conversion to UTF-8 can throw, because the system's names are under no obligation to be text.PathandPathBuffer— borrowed structure and the owning, growable buffer; component iteration where separator runs count once and an absolute path opens with an empty root component.PathBuffer::Popdrops the last component and leaves a root separator in place, so/usr/binbecomes/usr,/usrbecomes/, and/stays/, without allocating.- Parts and joins —
Parent,FileName,Stem,Extension,Join, and lexicalNormalize, each edge decided in writing — including thatx/..simplification is the truth about directories and a lie about symlinks, with the filesystem-true answer deferred to canonicalization. - Prefixes — the Windows family (drive, UNC share, verbatim) behind
PrefixLength,HasRootandIsAbsolute; the Unix systems have no prefixes, and nothing here folds case. - Two renderings, neither compromising —
OsStringView,OsString,PathandPathBufferimplementDisplayandDebug.Displayis the name as a reader should see it, with every native unit that is not text replaced by U+FFFD: lossy on purpose, for a message, never for reopening a file.Debugis the name as it is, quoted, with a Unix byte outside a well-formed sequence written\x{nn}and a Windows code unit with no partner written\u{xxxx}, so nothing is lost and two different names never render alike. A precision is refused by both rather than applied, because a truncated path is a different path and may be one that exists. The exact conversions and the filesystem operations are untouched by either.
Path and OsStringView are copyable borrowed values whose receivers are &self. Immutable OsString owns its native-unit block, so it is move-only: Clone allocates an independent block from the same allocator and terminates the program when that allocation fails, and OsString implements Core::Cloneable. PathBuffer prohibits copying, transfers with move, and releases its block through ~PathBuffer. Its storage fields are private, so its length changes only through its own operations.
Use Path(), OsStringView(), OsString(allocator), and PathBuffer(allocator) for empty values. Descriptive factories such as FromText, FromPath, Join, and Normalize retain their names and terminate the program when their storage cannot be had, as every owning text type does; OsStringView.ToText returns a String and throws TextError, because native units need not be UTF-8. Raw pointers remain only for native storage and scalar output slots, where nullable or stored addresses are required.
Index
Types
| Name | Summary |
|---|---|
OsUnit | The unit a native string is made of: a UTF-16 code unit on Windows, and a byte on the Unix systems. |
OsStringView | A borrowed run of native units. |
OsString | Native text that owns its units. |
Path | A borrowed path. |
ComponentIterator | A walk over a path's segments. |
PathBuffer | An owning, growable path. |
PrefixKind | The kind of prefix a path opens with. |
Functions
| Name | Summary |
|---|---|
IsSeparator | Whether unit separates path segments on this system. |
PreferredSeparator | The separator this system prefers when one has to be written. |
Join | A fresh buffer holding base with segment pushed onto it. |
Normalize | A fresh buffer holding path lexically simplified: separator runs collapsed to the preferred separator, . segments dropped, and .. resolved against the segment before it. |
PrefixLength | How many units of path are prefix, and which kind, reported through kind. |
HasRoot | Whether path has a root: a separator standing where the segments begin. |
IsAbsolute | Whether path names one place regardless of any current directory. |