WriteFormat functionv0.1.0

Source
Writes format into writer, with each {} replaced by the next argument.
pub func WriteFormat(
    writer: &var TextWriter,
    #Format() format: char8[..],
    ...
) -> ! FormatError

A placeholder is {}, or {:spec} carrying fill, alignment, sign, width, precision and style — see ParseFormatSpec for the grammar. {{ and }} stand for a literal brace, and are the only way to write one. The pattern is checked before any of it is written, so a pattern that is wrong produces no output rather than a prefix of one. What is checked is the pattern and the argument count, both of which are known at the call site; a value's own rendering can still fail partway, and what it managed to write stays written. format is marked #Format(), so when it is a string literal the compiler counts its placeholders against the arguments and a mismatch is reported while compiling rather than as ArgumentCountMismatch. Reports InvalidSpecification with the byte offset into format for a specification that does not parse, a brace the grammar does not allow, or a placeholder with no closing brace; ArgumentCountMismatch with the placeholders counted and the arguments supplied when the two differ; and otherwise whatever the destination or a value's own renderer reported, stopping at the first refusal. The first two are found before anything is written.

Parameters

NameTypeDescription
writer&var TextWriterthe destination
#Format() formatchar8[..]
...

Returns: success when the whole pattern and every argument were accepted