PathBuffer structv0.1.0

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

NameTypeDescription
data*var OsUnitThe units, or null before the first push.
lengthuintHow many units are in use.
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 ! TextError

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, or an empty one when the allocator refused

Source

Methods

Length

pub func Length(self: &PathBuffer) -> uint

How many units the buffer holds.

Returns: how many units the buffer holds

Source

IsEmpty

pub func IsEmpty(self: &PathBuffer) -> bool

Whether the buffer holds nothing.

Returns: whether the buffer holds no units

Source

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

Source

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.

NameTypeDescription
segmentOsStringViewthe component to append

Returns: nothing when the component was appended, or why not

Source

Release

pub func Release(self: &var PathBuffer)

Gives the block back and leaves an empty buffer.

Source

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.

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: &PathBuffer,
    writer: &var TextWriter,
    spec: FormatSpec
) -> ! 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(self: &var PathBuffer)

Gives the block back.

Source

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.

Source

Parameters

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

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
pathPaththe path to act on

Returns: the path with its redundant components resolved, or why it could not be