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
sourceimpl<'a> Printer<'a>
impl<'a> Printer<'a>
sourcepub fn with_context(
context: &'a Context,
printer_profile: PrinterProfile
) -> Result<Option<Printer<'a>>, Error>
pub fn with_context(
context: &'a Context,
printer_profile: PrinterProfile
) -> Result<Option<Printer<'a>>, Error>
Creates a new printer
Creates the printer with the given details, from the printer details provided, and in the given USB context.
sourcepub fn with_context_feeling_lucky(
context: &'a Context
) -> Result<Option<Printer<'a>>, Error>
pub fn with_context_feeling_lucky(
context: &'a Context
) -> Result<Option<Printer<'a>>, Error>
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.
sourcepub fn instruction(
&self,
instruction: &Instruction,
print_data: Option<&PrintData>
) -> Result<(), Error>
pub fn instruction(
&self,
instruction: &Instruction,
print_data: Option<&PrintData>
) -> Result<(), Error>
Print an instruction
You can pass optional printer data to the printer to fill in the dynamic parts of the instruction.
sourcepub fn print<T: AsRef<str>>(&self, content: T) -> Result<(), Error>
pub fn print<T: AsRef<str>>(&self, content: T) -> Result<(), Error>
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.
sourcepub fn println<T: AsRef<str>>(&self, content: T) -> Result<(), Error>
pub fn println<T: AsRef<str>>(&self, content: T) -> Result<(), Error>
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.
sourcepub fn jump(&self, n: u8) -> Result<(), Error>
pub fn jump(&self, n: u8) -> Result<(), Error>
Jumps n number of lines (to leave whitespaces). Basically n * '\n' passed to print
sourcepub fn cut(&self) -> Result<(), Error>
pub fn cut(&self) -> Result<(), Error>
Cuts the paper, in case the instruction is supported by the printer
sourcepub fn table_2(&self, rows: Vec<(String, String)>) -> Result<(), Error>
pub fn table_2(&self, rows: Vec<(String, String)>) -> Result<(), Error>
Prints a table with two columns. The sum of lengths of both strings
pub fn image(&self, escpos_image: EscposImage) -> Result<(), Error>
Auto Trait Implementations
impl<'a> RefUnwindSafe for Printer<'a>
impl<'a> Send for Printer<'a>
impl<'a> Sync for Printer<'a>
impl<'a> Unpin for Printer<'a>
impl<'a> UnwindSafe for Printer<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more