TextError enumv0.1.0
pub enum TextError: int32 {
OutOfMemory = 1,
LengthOverflow = 2,
InvalidUtf8 = 3,
NotABoundary = 4
}
Every case is a failure. An operation that can fail returns its result, or nothing, through a native fallible
T ! TextError, so success is the other channel rather than a case here.
Cases
| Name | Value | Description |
|---|---|---|
OutOfMemory | 1 | The allocator could not supply the storage. |
LengthOverflow | 2 | A length or offset computation passed what a uint can hold. |
InvalidUtf8 | 3 | The bytes are not well-formed UTF-8. |
NotABoundary | 4 | A byte offset that is not where a character starts, and so not a place text may be cut. |
Implements Display
TextError conforms to Display.
WriteDisplay
pub func WriteDisplay(
self: &TextError,
writer: &var TextWriter,
spec: FormatSpec
) -> ! FormatError
Writes the description of what went wrong, or no error for success.
The words are stable: they end up in logs and issue reports, and changing them later breaks every reader
quietly. They are a description and not a parsing contract — a program branches on the case, not the text.
Reports whatever the writer reported, and UnsupportedRequest for any style or precision.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole description was accepted
Implements Debug
TextError conforms to Debug.
WriteDebug
pub func WriteDebug(
self: &TextError,
writer: &var TextWriter,
spec: FormatSpec
) -> ! FormatError
Names the case, qualified by its type: TextError::InvalidUtf8.
Reports whatever the writer reported, and UnsupportedRequest for any style or precision.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole name was accepted
Related
FromAllocError
pub func FromAllocError(error: AllocError) -> TextError
The text error an allocator's failure becomes. Everything an allocator can refuse is a failure to supply storage as far as text is concerned; the distinctions the allocator draws are about the request, and this package makes no requests a caller could have made differently.
Parameters
| Name | Type | Description |
|---|---|---|
error | AllocError | why the allocator refused |
Returns: the same failure as a text error