pub struct Printer<'a> { /* private fields */ }
Expand description

Main escpos-rs structure

The printer represents the thermal printer connected to the computer.

use escpos_rs::{Printer, PrinterModel};
use libusb::{Context};

fn main() {
    // We create a usb contest for the printer
    let context = Context::new().unwrap();
    // We pass it to the printer
    let printer = match Printer::with_context(&context, PrinterModel::TMT20.profile()) {
        Ok(maybe_printer) => match maybe_printer {
            Some(printer) => printer,
            None => panic!("No printer was found :(")
        },
        Err(e) => panic!("Error: {}", e)
    };
    // Now we have a printer
}

Implementations

Creates a new printer

Creates the printer with the given details, from the printer details provided, and in the given USB context.

Guesses the printer, and connects to it (not meant for production)

Might help to find which printer you have if you have only one connected. The function will try to connect to a printer, based on the common ones recognized by this library.

Print an instruction

You can pass optional printer data to the printer to fill in the dynamic parts of the instruction.

Print some text. By default, there is line skipping with spaces as newlines (when the text does not fit). At the end, no newline is added.

Print some text.

By default, there is line skipping with spaces as newlines (when the text does not fit, assuming a width for at least one font was provided, else the text will split exacty where the line is full). At the end, no newline is added.

Jumps n number of lines (to leave whitespaces). Basically n * '\n' passed to print

Cuts the paper, in case the instruction is supported by the printer

Prints a table with two columns. The sum of lengths of both strings

Sends raw information to the printer

As simple as it sounds

printer.raw(&[0x01, 0x02])?;

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.