PathBuffer structv0.1.0
pub struct PathBuffer {
pub allocator: Allocator;
// private fields
}
Move-only: it prohibits copying and gives its block back with ~PathBuffer.
Storage invariant, which every unsafe block here relies on: length <= capacity; data is null exactly when
capacity is zero, and otherwise addresses a block of capacity units from allocator whose first length are
initialized.
Fields
| Name | Type | Description |
|---|---|---|
allocator | Allocator | Where the block came from, and where it goes back to. |
Constructors
PathBuffer
pub func PathBuffer(allocator: Allocator) -> PathBuffer
An empty buffer that has allocated nothing.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
Returns: an empty buffer that has taken no storage yet
Associated functions
FromPath
pub func FromPath(
allocator: Allocator,
path: Path
) -> PathBuffer
A buffer opening with path's units.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
path | Path | the path to act on |
Returns: a copy of path this buffer owns
Methods
Length
pub func Length(&self) -> uint
How many units the buffer holds.
Returns: how many units the buffer holds
IsEmpty
pub func IsEmpty(&self) -> bool
Whether the buffer holds nothing.
Returns: whether the buffer holds no units
AsPath
pub func AsPath(&self) -> Path
The buffer as a borrowed path, which is what every reading operation takes. The path borrows the buffer and must not outlive it or survive a push.
Returns: a borrowed path over the buffer's units
Push
pub func Push(&var self, segment: OsStringView)
Appends segment as one more component, supplying the separator where one is missing.
A segment that is itself absolute — opening with a separator — replaces the buffer instead of extending
it, which is what joining means everywhere paths are joined: join(a, /b) is /b.
| Name | Type | Description |
|---|---|---|
segment | OsStringView | the component to append |
Pop
pub func Pop(&var self)
Drops the last component, leaving a root separator in place.
Pop on /usr/bin leaves /usr, on /usr leaves /, and on / leaves /. Nothing is allocated.
Release
pub func Release(&var self)
Gives the block back and leaves an empty buffer.
Implements Display
PathBuffer conforms to Display.
WriteDisplay
pub func WriteDisplay(
&self,
writer: &var TextWriter,
spec: FormatSpec
) throws FormatError
The lossy rendering of the units the buffer owns.
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
PathBuffer conforms to Debug.
WriteDebug
pub func WriteDebug(
&self,
writer: &var TextWriter,
spec: FormatSpec
) throws FormatError
The exact, quoted rendering of the units the buffer owns.
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
Destructor
func ~PathBuffer(&var self)
Gives the block back.
Related
Join
pub func Join(
allocator: Allocator,
base: Path,
segment: OsStringView
) -> PathBuffer
A fresh buffer holding base with segment pushed onto it.
The join every path library means: a separator supplied where one is missing, and an absolute segment
replacing base entirely.
Parameters
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
base | Path | the path to extend |
segment | OsStringView | the component to append |
Returns: base with segment appended
Normalize
pub func Normalize(
allocator: Allocator,
path: Path
) -> PathBuffer
A fresh buffer holding path lexically simplified: separator runs collapsed to the preferred separator, .
segments dropped, and .. resolved against the segment before it.
Lexically is the load-bearing word. Dropping x/.. is the truth about directories and a lie about symbolic
links — a/link/.. need not be a when link points elsewhere — so this is for display, comparison and
deduplication, and the filesystem-true answer is canonicalization, which asks the system. A .. with nothing
before it survives in a relative path and vanishes at the root, where there is nowhere further up.
Parameters
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
path | Path | the path to act on |
Returns: the path with its redundant components resolved