pub struct Formatter { /* private fields */ }Expand description
Formatter for lists of DVI operations.
Most of the format depends only on the operation being printed, and for
that the std::fmt::Display implementation on Op suffices.
This type exists because two parts of the format depend on the operations
that came before:
-
Op::PushandOp::Popoperations introduce and remove indentation. -
Some operations are annotated with a comment giving runtime state. For example
Op::Moveis annotated with the current value of the variable being moved by, as that value does not appear in the operation.
The formatter tracks this state using the Values data structure:
let ops = vec![
dvi::Op::SetVar(dvi::Var::Y, 300),
dvi::Op::Move(dvi::Var::Y),
];
let mut formatter: dvi::display::Formatter = Default::default();
let mut out = String::new();
for op in &ops {
formatter.write_op(&mut out, op, 0).unwrap();
}
assert_eq!(out, "set_var(y, 300)\nmove(y) // 300\n");Implementations§
Source§impl Formatter
impl Formatter
Sourcepub fn write_op<W: Write>(
&mut self,
w: &mut W,
op: &Op,
byte_offset: usize,
) -> Result
pub fn write_op<W: Write>( &mut self, w: &mut W, op: &Op, byte_offset: usize, ) -> Result
Write a single operation, followed by a newline.
Operations must be provided in the order they appear in the DVI data,
otherwise the indentation and the comments will be wrong.
The byte offset is the offset of the operation in the DVI data;
it is only printed if the Options::byte_offsets option is set.