OsString structv0.1.0
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.
| 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
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.
| 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
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.
| 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
Methods
Length
pub func Length(&self) -> uint
How many native units the text holds.
Returns: how many units the value holds
IsEmpty
pub func IsEmpty(&self) -> bool
Whether the text holds nothing.
Returns: whether it holds no units at all
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
Clear
pub func Clear(&var self)
Gives the block back and leaves text of no length.
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
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.
| 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,
writer: &var TextWriter,
spec: FormatSpec
) throws 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(&var self)
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.