OsString structv0.1.0
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.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
Returns: an empty owned string that has taken no storage yet
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.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
view | OsStringView | the borrowed text to copy |
Returns: a copy of view this string owns, or an empty one when the allocator refused
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.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
text | char8[..] | the text to act on |
Returns: the text converted to the platform's own units, or why it could not be
Methods
Length
pub func Length(self: &OsString) -> uint
How many native units the text holds.
Returns: how many units the value holds
IsEmpty
pub func IsEmpty(self: &OsString) -> bool
Whether the text holds nothing.
Returns: whether it holds no units at all
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
Clear
pub func Clear(self: &var OsString)
Gives the block back and leaves text of no length.
Operators
=
pub func =(self: &var OsString, other: &OsString)
Deep-copies native units into independent storage from the same allocator.
| Name | Type | Description |
|---|---|---|
other | &OsString | the value to compare against |
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.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole name was accepted
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.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole name was accepted
Destructor
func ~OsString(self: &var OsString)
Gives the block back.
Related
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.