Module display

Module display 

Source
Expand description

Human readable formatting of DVI operations.

The format is designed to be easy to read and, sometime in the future, e parseable back into the same list of Op values. Each operation is printed like a function call whose name is the snake case version of the operation, and whose arguments are the payload of the operation:

assert_eq!(dvi::display::format_ops([Op::SetVar(Var::W, 300)]), "set_var(w, 300)\n");

Operations with no payload are printed without parentheses:

assert_eq!(dvi::display::format_ops([Op::Push, Op::Pop]), "push\npop\n");

Operations with a large payload place each argument on its own line:

assert_eq!(
    dvi::display::format_ops([Op::Preamble{
        dvi_format: 2,
        unit_numerator: 25400000,
        unit_denominator: 473628672,
        magnification: 1000,
        comment: "Texcraft".into(),
    }]),
    r#"preamble(
  dvi_format: 2,
  unit_numerator: 25400000,
  unit_denominator: 473628672,
  magnification: 1000,
  comment: "Texcraft",
)
"#,
);

Finally, Op::Push and Op::Pop operations introduce indentation, and some operations are annotated with a comment describing runtime state that is not visible in the operation itself:

assert_eq!(
    dvi::display::format_ops([
        Op::SetVar(Var::W, 300),
        Op::Push,
        Op::Move(Var::W),
        Op::Pop,
    ]),
    "set_var(w, 300)\npush\n  move(w)  // 300\npop\n",
);

Indentation can be disabled, and byte offsets can be printed, using the Options type.

Structs§

Formatter
Formatter for lists of DVI operations.
Options
Options for the Formatter.

Functions§

format_ops
Format a list of operations as a string, using the default Options.