Path structv0.1.0
pub struct Path {
pub name: OsStringView;
}
Copy, owning nothing: structure over an OsStringView's units.
Fields
| Name | Type | Description |
|---|---|---|
name | OsStringView | The name, exactly as the system would hold it. |
Constructors
Path
pub func Path() -> Path
A path over nothing.
Returns: an empty path
Associated functions
FromView
pub func FromView(view: OsStringView) -> Path
A path over view's units as they stand.
| Name | Type | Description |
|---|---|---|
view | OsStringView | the borrowed text to copy |
Returns: a path over those units, which it does not copy
Methods
Parent
pub func Parent(&self) -> Path?
This path without its last component, or none where nothing is left to remove.
The parent of /a is /, and the root's parent is none: the root is not inside anything. The parent of
a bare segment is the empty path, which is what lets a loop walk parents to a fixed end.
Returns: the path without its last component, or none when there is none to remove
FileName
pub func FileName(&self) -> OsStringView?
The last component's name, or none for the empty path and the root.
Trailing separators are ignored: a/b/ names b, because that is what everything from shells to
libraries has always meant by it.
Returns: the last component, or none for a root or a path ending in a separator
Stem
pub func Stem(&self) -> OsStringView?
The file name before its extension, or none where there is no file name.
A leading dot is part of the name, not an extension marker: the stem of .bashrc is .bashrc. Of
a.tar.gz it is a.tar — one extension comes off, the last.
Returns: the file name without its extension, or none when there is no file name
Extension
pub func Extension(&self) -> OsStringView?
The extension after the last dot, without the dot, or none where there is none.
none for .bashrc and for Makefile alike: a name that is all extension has none.
Returns: the file name's extension without the dot, or none when it has none
Length
pub func Length(&self) -> uint
How many native units the path spans.
Returns: how many units the path holds
IsEmpty
pub func IsEmpty(&self) -> bool
Whether the path is empty, which names nothing at all.
Returns: whether the path holds no units
AsView
pub func AsView(&self) -> OsStringView
The name under the structure.
Returns: the path's units, borrowed
Equals
pub func Equals(&self, other: Path) -> bool
Whether two paths are the same units.
Lexical, not semantic: a/b and a//b name the same file and are different paths here. Making them equal
is normalization's job, asked for by name.
| Name | Type | Description |
|---|---|---|
other | Path | the value to compare against |
Returns: whether both hold the same units in the same order, without normalizing either
Components
pub func Components(&self) -> ComponentIterator
A walk over the path's components, first to last.
Returns: a cursor over the path's components
Implements Display
Path conforms to Display.
WriteDisplay
pub func WriteDisplay(
&self,
writer: &var TextWriter,
spec: FormatSpec
) throws FormatError
The lossy rendering of the path's units.
The separators are written as they stand: a path is shown as it is, not normalized towards the platform's
preferred separator, because which separators a name contains is part of what it is.
The failures OsStringView::WriteDisplay reports.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole path was accepted
Implements Debug
Path conforms to Debug.
WriteDebug
pub func WriteDebug(
&self,
writer: &var TextWriter,
spec: FormatSpec
) throws FormatError
The exact, quoted rendering of the path's units.
The failures OsStringView::WriteDebug reports.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole path was accepted
Related
ComponentIterator
pub struct ComponentIterator {
// private fields
}
A walk over a path's segments.
Runs of separators count as one, and a trailing separator ends the walk rather than yielding an empty segment:
a//b/ walks as a, b. A leading separator is the root, which the walk reports as an empty first component
so that an absolute path is distinguishable from a relative one holding the same segments.
Methods
Next
pub func Next(&var self) -> OsStringView?
The next component, or none when the walk is done.
Returns: the next component, or none at the end