std/format¶
module format
The formats, how bytes are read as values and how values are written as text, and the codec contracts over them.
A format is a type narrowing Format, the category core declares. It
names an external representation and, where it applies, its framing:
Lines is text framed one record per line, JsonLines one JSON document
per line. A format is not the text it encodes, so none narrows String,
and it is not Format<T>, since one format encodes many value
structures. Whether what is read ends is a property of the source, not of
the format: source(file(p), Lines) is a Seq<String> and
source(stdin, Lines) a Stream<String>.
A String is always UTF-8. Every format that holds text reads and writes
UTF-8, and decoding bytes that are not UTF-8 is a decoding error.
Text— The plain-text format: read, the whole input is oneString; written, a value is its display text, and aStringits characters as they are.Lines— The format of text framed one record per line: read, each line is oneString; written, each element of a collection is one line:[1, 2] | linesis"1\n2".Hql— The format of HQL's own value notation:{a: 1, b: [true]} | hqlis"{a: 1, b: [true]}".Markdown— The Markdown format: read, the whole input is oneString; written, a collection is a list, one item per element:[1, 2] | markdownis"- 1\n- 2".Hmd— The HyperMarkDown format, a narrowing ofMarkdown: every HyperMarkDown text is Markdown, and a value is written in it as inMarkdown.Json— The JSON format: read, each document is oneDatavalue; written, a value is one indented JSON document.JsonLines— The JSON Lines format, one JSON document per line: read, each line is oneDatavalue; written, each element of a collection is one line of compact JSON:[{a: 1}, {a: 2}] | jsonlinesis"{\"a\":1}\n{\"a\":2}".Yaml— The YAML format: read, each document of the input,---separating them, is oneDatavalue; written, a value is one YAML document.Csv— The comma-separated values format, with a header row: read, each row is oneDatavalue whose fields, named by the header, holdStrings; written, a collection of records or aTableis the header and one row per element.D2— The D2 diagram format, which writes aGraph, or aDatavalue holding one, and nothing else.Mermaid— The Mermaid diagram format, which writes aGraph, or aDatavalue holding one, and nothing else.DiagnosticText— The text form of aDiagnostic(HQL-0045), which writes a diagnostic, or a sequence of them, and nothing else: each one's heading,phase severity[kind]: message, its origin and the fields that apply, then a count per severity when there is more than one.Table— Rows of typeRunder ordered columns: the shape every format's encoder writes as a table.Decoder— The contract that a format's records are read as values ofT:source(e, F)gives theTofF's decoder.Encoder— The contract that values ofTare written as records of a format:format(x, F)takes the typesF's encoders cover.format— The formats, how bytes are read as values and how values are written as text, and the codec contracts over them.text—xencoded asText:x | textisformat(x, Text).hql—xencoded asHql:x | hqlisformat(x, Hql).markdown—xencoded asMarkdown:x | markdownisformat(x, Markdown).hmd—xencoded asHmd:x | hmdisformat(x, Hmd).json—xencoded asJson:x | jsonisformat(x, Json).yaml—xencoded asYaml:x | yamlisformat(x, Yaml).csv—xencoded asCsv:x | csvisformat(x, Csv).lines—xencoded asLines:x | linesisformat(x, Lines).jsonlines—xencoded asJsonLines:x | jsonlinesisformat(x, JsonLines).d2—xencoded asD2:x | d2isformat(x, D2).mermaid—xencoded asMermaid:x | mermaidisformat(x, Mermaid).
Implementations¶
impl Decoder<String> for Text
impl Decoder<String> for Lines
impl Decoder<String> for Hql
impl Decoder<String> for Markdown
impl Decoder<String> for Hmd
Text, Lines, Hql, Markdown and Hmd are read as Strings.
impl Decoder<Data> for Json
impl Decoder<Data> for JsonLines
impl Decoder<Data> for Yaml
impl Decoder<Data> for Csv
Json, JsonLines, Yaml and Csv are read as Data.
impl<T> Encoder<T> for Text
impl<T> Encoder<T> for Lines
impl<T> Encoder<T> for Hql
impl<T> Encoder<T> for Markdown
impl<T> Encoder<T> for Hmd
impl<T> Encoder<T> for Json
impl<T> Encoder<T> for JsonLines
impl<T> Encoder<T> for Yaml
impl<T> Encoder<T> for Csv
Text, Lines, Hql, Markdown, Hmd, Json, JsonLines, Yaml
and Csv write a value of any type.
impl Encoder<Graph> for D2
impl Encoder<Data> for D2
impl Encoder<Graph> for Mermaid
impl Encoder<Data> for Mermaid
D2 and Mermaid describe graphs: they write a Graph, or a Data
value holding one.
impl Encoder<Diagnostic> for DiagnosticText
DiagnosticText writes a Diagnostic, and a sequence of them one after
another.