TextError enumv0.1.0

Source
What went wrong.
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

NameValueDescription
OutOfMemory1The allocator could not supply the storage.
LengthOverflow2A length or offset computation passed what a uint can hold.
InvalidUtf83The bytes are not well-formed UTF-8.
NotABoundary4A 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.

NameTypeDescription
writer&var TextWriterthe destination
specFormatSpecwhat the placeholder asked for

Returns: success when the whole description was accepted

Source

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.

NameTypeDescription
writer&var TextWriterthe destination
specFormatSpecwhat the placeholder asked for

Returns: success when the whole name was accepted

Source

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.

Source

Parameters

NameTypeDescription
errorAllocErrorwhy the allocator refused

Returns: the same failure as a text error