PathBuffer structv0.1.0
pub struct PathBuffer {
pub data: *var OsUnit;
pub length: uint;
pub allocator: Allocator;
// private fields
}
Move-only: it prohibits copying and gives its block back with ~PathBuffer.
Fields
| Name | Type | Description |
|---|---|---|
data | *var OsUnit | The units, or null before the first push. |
length | uint | How many units are in use. |
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 ! TextError
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, or an empty one when the allocator refused
Methods
Length
pub func Length(self: &PathBuffer) -> uint
How many units the buffer holds.
Returns: how many units the buffer holds
IsEmpty
pub func IsEmpty(self: &PathBuffer) -> bool
Whether the buffer holds nothing.
Returns: whether the buffer holds no units
AsPath
pub func AsPath(self: &PathBuffer) -> 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(
self: &var PathBuffer,
segment: OsStringView
) -> ! TextError
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 |
Returns: nothing when the component was appended, or why not
Release
pub func Release(self: &var PathBuffer)
Gives the block back and leaves an empty buffer.
Implements Display
PathBuffer conforms to Display.
WriteDisplay
pub func WriteDisplay(
self: &PathBuffer,
writer: &var TextWriter,
spec: FormatSpec
) -> ! 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: &PathBuffer,
writer: &var TextWriter,
spec: FormatSpec
) -> ! 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(self: &var PathBuffer)
Gives the block back.
Related
Join
pub func Join(
allocator: Allocator,
base: Path,
segment: OsStringView
) -> PathBuffer ! TextError
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, or why it could not be
Normalize
pub func Normalize(
allocator: Allocator,
path: Path
) -> PathBuffer ! TextError
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, or why it could not be