Display interfacev0.1.0

Source
The text a value has for a reader.
pub interface Display {
    func WriteDisplay(
        writer: &var TextWriter,
        spec: FormatSpec
    ) -> ! FormatError;
}

An implementation writes into the destination it is handed and allocates no working storage of its own. A value whose rendering genuinely requires scratch space takes an allocator through a separate, explicit conversion instead of implementing this.

Requirements

WriteDisplay

func WriteDisplay(
    writer: &var TextWriter,
    spec: FormatSpec
) -> ! FormatError

Writes this value's text under spec. Returns whatever the writer reported, or UnsupportedRequest when spec asks for something this value does not support, or ValueOutOfRange when the value cannot be represented in the form requested. An implementation stops at the first failed write rather than continuing to a destination that has already refused something.

NameTypeDescription
writer&var TextWriterthe destination
specFormatSpecwhat the placeholder asked for

Returns: success when the value's complete text was accepted

Source

Implementations

TypeSummary
TextFailureKindThe ways text handling fails, with no case for success.
FormatErrorWhy a formatting operation did not produce the text it was asked for.
StringText that owns its bytes.
StringViewA borrowed run of bytes that has been checked to be UTF-8.
TextErrorWhat went wrong.
Utf8ErrorWhat was wrong with a byte sequence.

WriteValue

pub func WriteValue(
    writer: &var TextWriter,
    value: Display,
    spec: FormatSpec
) -> ! FormatError

Writes value under spec through its Display implementation. A named entry point for rendering one value, so a caller with a value and a writer needs no placeholder pattern to put them together.

Source

Parameters

NameTypeDescription
writer&var TextWriterthe destination
valueDisplaythe value to render, borrowed for the call
specFormatSpecwhat to render it under

Returns: whatever the value's implementation reported