v0.4.0

OsString structv0.1.0

Source
Native text that owns its units.
pub struct OsString {
    // private fields
}

Move-only: it owns its native-unit block and gives it back when it dies. Clone makes an independent copy. Storage invariant, which every unsafe block here relies on: data is null exactly when length is zero, and otherwise addresses a block of length initialized units from allocator.

Constructors

OsString

pub func OsString(allocator: Allocator) -> OsString

Native text of no length, which has allocated nothing.

NameTypeDescription
allocatorAllocatorwhere the storage comes from

Returns: an empty owned string that has taken no storage yet

Source

Associated functions

FromView

pub func FromView(
    allocator: Allocator,
    view: OsStringView
) -> OsString

An owning copy of what view spans, exactly as it stands. This is the lossless direction: whatever the system handed over survives, valid text or not. Terminates the program when the copy cannot be made.

NameTypeDescription
allocatorAllocatorwhere the storage comes from
viewOsStringViewthe borrowed text to copy

Returns: a copy of view this string owns

Source

FromText

pub func FromText(
    allocator: Allocator,
    text: char8[..]
) -> OsString

An owning native copy of UTF-8 text. The direction that always succeeds: valid text encodes into either representation, byte for byte on the Unix systems and through UTF-16 on Windows. It terminates the program when the allocation fails. The bytes must be well-formed UTF-8, which everything in Rux/Text produces and vouches for.

NameTypeDescription
allocatorAllocatorwhere the storage comes from
textchar8[..]the text to act on

Returns: the text converted to the platform's own units

Source

Methods

Length

pub func Length(&self) -> uint

How many native units the text holds.

Returns: how many units the value holds

Source

IsEmpty

pub func IsEmpty(&self) -> bool

Whether the text holds nothing.

Returns: whether it holds no units at all

Source

View

pub func View(&self) -> OsStringView

A view over this text, which is what everything read-only takes.

Returns: a borrowed view of the owned units

Source

Clear

pub func Clear(&var self)

Gives the block back and leaves text of no length.

Source

Implements Cloneable

OsString conforms to Cloneable.

Clone

pub func Clone(&self) -> OsString

An independent copy in a block of its own from the same allocator. Borrows the source and leaves it unchanged. Terminates the program when the allocator refuses, since the copy it promises cannot be made. Runs in time proportional to the length.

Returns: a copy that owns its own units

Source

Implements Display

OsString conforms to Display.

WriteDisplay

pub func WriteDisplay(
    &self,
    writer: &var TextWriter,
    spec: FormatSpec
) throws FormatError

The lossy rendering of the units this text owns. The failures OsStringView::WriteDisplay reports.

NameTypeDescription
writer&var TextWriterthe destination
specFormatSpecwhat the placeholder asked for

Returns: success when the whole name was accepted

Source

Implements Debug

OsString conforms to Debug.

WriteDebug

pub func WriteDebug(
    &self,
    writer: &var TextWriter,
    spec: FormatSpec
) throws FormatError

The exact rendering of the units this text owns. The failures OsStringView::WriteDebug reports.

NameTypeDescription
writer&var TextWriterthe destination
specFormatSpecwhat the placeholder asked for

Returns: success when the whole name was accepted

Source

Destructor

func ~OsString(&var self)

Gives the block back.

Source

OsUnit

// Windows
pub type OsUnit = uint16

// Linux · macOS · FreeBSD
pub type OsUnit = char8

The unit a native string is made of: a UTF-16 code unit on Windows, and a byte on the Unix systems.

Source