Formatter

Struct Formatter 

Source
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::Push and Op::Pop operations introduce and remove indentation.

  • Some operations are annotated with a comment giving runtime state. For example Op::Move is 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

Source

pub fn new(options: Options) -> Self

Create a new formatter with the provided options.

Source

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.

Source

pub fn options(&self) -> &Options

Get the options the formatter was created with.

Source

pub fn values(&self) -> &Values

Get the values the formatter has accumulated so far.

Trait Implementations§

Source§

impl Default for Formatter

Source§

fn default() -> Formatter

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.