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_idis the ordinal the next shape added takes, which is where numbering resumes rather than a count of what was read:1,7and9undernext_id: 10hands back10. It is a nonzero ordinal, because zero is not an identity;"next_id": 0is refused here rather than seeded with something no shape can carry.shapesis the figures in drawing order, empty or not, the last front-most and deciding a shared cell first. Each entry names akindand carries theidits 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§
- Parse
Error - A description that could not be read.
- Serialize
Error - A description that could not be serialized.