v0.4.0

PathBuffer structv0.1.0

Source
An owning, growable path.
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

NameTypeDescription
allocatorAllocatorWhere 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.

NameTypeDescription
allocatorAllocatorwhere the storage comes from

Returns: an empty buffer that has taken no storage yet

Source

Associated functions

FromPath

pub func FromPath(
    allocator: Allocator,
    path: Path
) -> PathBuffer

A buffer opening with path's units.

NameTypeDescription
allocatorAllocatorwhere the storage comes from
pathPaththe path to act on

Returns: a copy of path this buffer owns

Source

Methods

Length

pub func Length(&self) -> uint

How many units the buffer holds.

Returns: how many units the buffer holds

Source

IsEmpty

pub func IsEmpty(&self) -> bool

Whether the buffer holds nothing.

Returns: whether the buffer holds no units

Source

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

Source

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.

NameTypeDescription
segmentOsStringViewthe component to append

Source

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.

Source

Release

pub func Release(&var self)

Gives the block back and leaves an empty buffer.

Source

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.

NameTypeDescription
writer&var TextWriterthe destination
specFormatSpecwhat the placeholder asked for

Returns: success when the whole path was accepted

Source

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.

NameTypeDescription
writer&var TextWriterthe destination
specFormatSpecwhat the placeholder asked for

Returns: success when the whole path was accepted

Source

Destructor

func ~PathBuffer(&var self)

Gives the block back.

Source

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.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
basePaththe path to extend
segmentOsStringViewthe 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.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
pathPaththe path to act on

Returns: the path with its redundant components resolved