OsString structv0.1.0

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

Copyable with value semantics: each copy owns an independent native-unit block.

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 ! TextError

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. It fails with OutOfMemory 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, or an empty one when the allocator refused

Source

FromText

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

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 fails only when the allocation does. 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, or why it could not be

Source

Methods

Length

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

How many native units the text holds.

Returns: how many units the value holds

Source

IsEmpty

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

Whether the text holds nothing.

Returns: whether it holds no units at all

Source

View

pub func View(self: &OsString) -> 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(self: &var OsString)

Gives the block back and leaves text of no length.

Source

Operators

=

pub func =(self: &var OsString, other: &OsString)

Deep-copies native units into independent storage from the same allocator.

NameTypeDescription
other&OsStringthe value to compare against

Source

Implements Display

OsString conforms to Display.

WriteDisplay

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

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