escposify/lib.rs
1//! escposify - A ESC/POS driver for Rust
2//!
3//! ## Examples
4//!
5//! ### sample.rs
6//!
7//! Write to a temporary file using [device::File].
8//! ```rust
9//! use std::io;
10//!
11//! use escposify::device::File;
12//! use escposify::printer::Printer;
13//!
14//! use tempfile::NamedTempFileOptions;
15//!
16//! fn main() -> io::Result<()> {
17//! let tempf = NamedTempFileOptions::new().create().unwrap();
18//!
19//! let file = File::from(tempf);
20//! let mut printer = Printer::new(file, None, None);
21//!
22//! printer
23//! .chain_font("C")?
24//! .chain_align("lt")?
25//! .chain_style("bu")?
26//! .chain_size(0, 0)?
27//! .chain_text("The quick brown fox jumps over the lazy dog")?
28//! .chain_text("敏捷的棕色狐狸跳过懒狗")?
29//! .chain_barcode("12345678", "EAN8", "", "", 0, 0)?
30//! .chain_feed(1)?
31//! .chain_cut(false)?
32//! .flush()
33//! }
34//! ```
35//!
36//! ### Printing to /dev/usb/lp0
37//!
38//! When writing to a file ensure that `File::options().append(true)` is set otherwise writing is not possible.
39//! ```no_run
40//! use std::fs::File;
41//! use std::io;
42//!
43//! use escposify::printer::Printer;
44//!
45//! fn main() -> io::Result<()> {
46//! let device_file = File::options().append(true).open("/dev/usb/lp0").unwrap();
47//!
48//! let file = escposify::device::File::from(device_file);
49//! let mut printer = Printer::new(file, None, None);
50//!
51//! printer
52//! .chain_size(0,0)?
53//! .chain_text("The quick brown fox jumps over the lazy dog")?
54//! .chain_feed(1)?
55//! .chain_cut(false)?
56//! .flush()
57//! }
58//! ```
59//!
60//! ### Writing to the stdout
61//!
62//! Understandably not all options work here (alignment, fonts, chain_cut etc.)
63//! but for quick debugging and prototyping this is a good option
64//! as it saves tons of time when working on the logic of your implementation.
65//!
66//! ```rust
67//! use std::io::{self, stdout};
68//! use escposify::printer::Printer;
69//!
70//! fn main() -> io::Result<()> {
71//!
72//! let mut printer = Printer::new(stdout(), None, None);
73//!
74//! printer
75//! .chain_feed(2)?
76//! .chain_text("The quick brown fox jumps over the lazy dog")?
77//! .chain_text("敏捷的棕色狐狸跳过懒狗")?
78//! .chain_feed(1)?
79//! .flush()
80//! }
81//! ```
82//!
83//! ### Printing to a printer via USB
84//!
85//! ```no_run
86//! use std::io;
87//! use escposify::printer::Printer;
88//! use escposify::device::Usb;
89//!
90//! fn main() -> io::Result<()> {
91//! let product_id = 0xa700;
92//! let vendor_id = 0x0525;
93//! let usb = Usb::new(vendor_id, product_id)?;
94//!
95//! let mut printer = Printer::new(usb, None, None);
96//!
97//! printer
98//! .chain_feed(5)?
99//! .chain_font("C")?
100//! .chain_align("lt")?
101//! .chain_style("bu")?
102//! .chain_size(0, 0)?
103//! .chain_text("The quick brown fox jumps over the lazy dog")?
104//! .chain_barcode("12345678", "EAN8", "", "", 0, 0)?
105//! .chain_feed(5)?
106//! .chain_cut(false)?
107//! .flush()
108//! }
109//! ```
110
111pub mod consts;
112pub mod device;
113pub mod img;
114pub mod printer;