Skip to main content

Crate monospace_description

Crate monospace_description 

Source
Expand description

The diagram description format: JSON deserialized into a monospace_diagram::Diagram or serialized back from one.

Two calls do the whole of it — parse takes the text and hands back the diagram, and serialize takes the diagram and hands back the formatted JSON text — and every type behind those calls is private to this crate. The public surface is four things: parse, ParseError, serialize and SerializeError. Nothing here reaches a file, a terminal or a screen: a caller that wants to read from or write to disk reads or writes the disk itself and hands the text over. Nothing here names a window either, because which part of a diagram to draw is the caller’s question and the window is the caller’s.

This crate is a layer above the diagram, and it knows nothing of the editing layer. Both hang off monospace-diagram and neither depends on the other; what would join them is a convenience that opens a file into a session, and that belongs to whoever needs it rather than to either layer. See docs/diagram-model.md.

§The envelope

One file is one JSON object of two fields, and both are required:

{
  "next_id": 3,
  "shapes": []
}
  • next_id is the ordinal the next shape added takes, which is where numbering resumes rather than a count of what was read: 1, 7 and 9 under next_id: 10 hands back 10. It is a nonzero ordinal, because zero is not an identity; "next_id": 0 is refused here rather than seeded with something no shape can carry.
  • shapes is the figures in drawing order, empty or not, the last front-most and deciding a shared cell first. Each entry names a kind and carries the id its shape is held under.

There is no canvas. A description that still carries one is read, and the canvas ignored: there is no writer, so nothing outside this repository has ever produced a file, and a stricter error would be a change to wording that fifteen tests assert verbatim for no gain. The window a picture is drawn into is the caller’s, named on the command line or on the line that opens a render marker — see docs/diagram-model.md, which holds that the diagram measures nothing and sizes nothing.

§What is not here

No file. Neither parse nor serialize takes a path, so nothing in this crate reaches a filesystem — which is also what keeps it portable by naming rather than by anything it avoids.

Structs§

ParseError
A description that could not be read.
SerializeError
A description that could not be serialized.

Functions§

parse
Reads a description and hands back the diagram it holds, and nothing else.
serialize
Serializes diagram into formatted JSON matching the description format read by parse.