Struct PrinterProfile

Source
pub struct PrinterProfile { /* private fields */ }
Expand description

Details required to connect and print

In order to use the full functionality of the library, some information should be provided regarding the printer. The bare minimum information needed is the product id and the vendor id.

Implementations§

Source§

impl PrinterProfile

Source

pub fn new( printer_connection_data: PrinterConnectionData, columns_per_font: HashMap<Font, u8>, width: u16, ) -> PrinterProfile

Create custom printing details

Not recommended to use, as it contains a lot of arguments. See one of the builders instead (at the moment, only usb_builder and terminal_builder available).

Source

pub fn usb_builder(vendor_id: u16, product_id: u16) -> PrinterProfileBuilder

Creates a PrinterProfileBuilder set for usb printing.

Equivalent to a call to PrinterProfileBuilder’s new_usb function.

use escpos_rs::PrinterProfile;
// Creates a minimum data structure to connect to a printer
let printer_profile = PrinterProfile::usb_builder(0x0001, 0x0001).build();
Source

pub fn terminal_builder() -> PrinterProfileBuilder

Creates a PrinterProfileBuilder set for terminal printing

Equivalent to a call to PrinterProfileBuilder’s new_terminal function.

use escpos_rs::PrinterProfile;
// Creates a minimum data structure to connect to a printer
let printer_profile = PrinterProfile::terminal_builder().build();
Examples found in repository?
examples/basic.rs (line 4)
3fn main() {
4    let printer_profile = PrinterProfile::terminal_builder().with_font_width(Font::FontA, 20).build();
5    // We pass it to the printer
6    let printer = match Printer::new(printer_profile) {
7        Ok(maybe_printer) => match maybe_printer {
8            Some(printer) => printer,
9            None => panic!("No printer was found :(")
10        },
11        Err(e) => panic!("Error: {}", e)
12    };
13    
14    // We print simple text
15    match printer.println("Hello, world!") {
16        Ok(_) => (),
17        Err(e) => println!("Error: {}", e)
18    }
19}
More examples
Hide additional examples
examples/space_split.rs (line 4)
3fn main() {
4    let printer_profile = PrinterProfile::terminal_builder().with_font_width(Font::FontA, 32).build();
5    // We pass it to the printer
6    let mut printer = match Printer::new(printer_profile) {
7        Ok(maybe_printer) => match maybe_printer {
8            Some(printer) => printer,
9            None => panic!("No printer was found :(")
10        },
11        Err(e) => panic!("Error: {}", e)
12    };
13    // We set word splitting
14    printer.set_space_split(true);
15
16    // We print simple text
17    match printer.println("Really long sentence that should be splitted into three components, yay!") {
18        Ok(_) => (),
19        Err(e) => println!("Error: {}", e)
20    }
21}
examples/tables.rs (line 4)
3fn main() {
4    let printer_profile = PrinterProfile::terminal_builder().with_font_width(Font::FontA, 20).build();
5    // We pass it to the printer
6    let mut printer = match Printer::new(printer_profile) {
7        Ok(maybe_printer) => match maybe_printer {
8            Some(printer) => printer,
9            None => panic!("No printer was found :(")
10        },
11        Err(e) => panic!("Error: {}", e)
12    };
13    // We set word splitting
14    printer.set_space_split(true);
15    
16    println!("Table with two columns:");
17    match printer.duo_table(("Product", "Price"), vec![
18        ("Milk", "5.00"),
19        ("Cereal", "10.00")
20    ]) {
21        Ok(_) => (),
22        Err(e) => println!("Error: {}", e)
23    }
24
25    println!("Table with three columns:");
26    match printer.trio_table(("Product", "Price", "Qty."), vec![
27        ("Milk", "5.00", "3"),
28        ("Cereal", "10.00", "1")
29    ]) {
30        Ok(_) => (),
31        Err(e) => println!("Error: {}", e)
32    }
33}

Trait Implementations§

Source§

impl Clone for PrinterProfile

Source§

fn clone(&self) -> PrinterProfile

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PrinterProfile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.