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
impl PrinterProfile
Sourcepub fn new(
printer_connection_data: PrinterConnectionData,
columns_per_font: HashMap<Font, u8>,
width: u16,
) -> PrinterProfile
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).
Sourcepub fn usb_builder(vendor_id: u16, product_id: u16) -> PrinterProfileBuilder
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();
Sourcepub fn terminal_builder() -> PrinterProfileBuilder
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
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
impl Clone for PrinterProfile
Source§fn clone(&self) -> PrinterProfile
fn clone(&self) -> PrinterProfile
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for PrinterProfile
impl RefUnwindSafe for PrinterProfile
impl Send for PrinterProfile
impl Sync for PrinterProfile
impl Unpin for PrinterProfile
impl UnwindSafe for PrinterProfile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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