pub struct CustomPrinter { /* private fields */ }
Expand description
The main struct to construct printing commands and accomplish actual printing.
The APIs are designed to be able to concatenate one after the other.
§Examples
let mut printer = CustomPrinter::new("/dev/usb/lp0").unwrap();
printer
.bit_image(
"logo.bmp",
BitImageMode::Dots24DoubleDensity
)
.unwrap()
.cut_paper(CutType::PartialCut)
.run()
.unwrap()
.bit_image(
"greeting.bmp",
BitImageMode::Dots24DoubleDensity
)
.unwrap()
.cut_paper(CutType::TotalCut)
.run()
.unwrap();
Implementations§
Source§impl CustomPrinter
impl CustomPrinter
Sourcepub fn new(dev: &str) -> Result<Self, Error>
pub fn new(dev: &str) -> Result<Self, Error>
Create a new CustomPrinter
with the device node dev
.
NOTE: Device node dev
must be readable and writable by current user.
§Examples
CustomPrinter::new("/dev/usb/lp0")
Examples found in repository?
3fn main() {
4 // Replace /dev/null with actual device node when the printer is connected
5 // e.g.: /dev/usb/lp0
6 let mut printer = CustomPrinter::new("/dev/null").unwrap();
7 printer
8 .bit_image(
9 "tests/data/Thermal_Test_Image.png",
10 BitImageMode::Dots24DoubleDensity,
11 )
12 .unwrap()
13 .cut_paper(CutType::TotalCut)
14 .run()
15 .unwrap();
16}
Sourcepub fn bit_image(
&mut self,
path: &str,
mode: BitImageMode,
) -> Result<&mut Self, Error>
pub fn bit_image( &mut self, path: &str, mode: BitImageMode, ) -> Result<&mut Self, Error>
Append commands for printing a bit image from path
in mode
. See BitImageMode
for supported modes.
NOTE: Because opening and reading the image file may fail, so the return Self is wrapped in a Result
and needs to be unwrapped before concatenating with other constructing functions.
§Examples
printer
.bit_image(
"tests/data/Thermal_Test_Image.png",
BitImageMode::Dots24DoubleDensity
)
.unwrap();
Examples found in repository?
3fn main() {
4 // Replace /dev/null with actual device node when the printer is connected
5 // e.g.: /dev/usb/lp0
6 let mut printer = CustomPrinter::new("/dev/null").unwrap();
7 printer
8 .bit_image(
9 "tests/data/Thermal_Test_Image.png",
10 BitImageMode::Dots24DoubleDensity,
11 )
12 .unwrap()
13 .cut_paper(CutType::TotalCut)
14 .run()
15 .unwrap();
16}
Sourcepub fn cut_paper(&mut self, cut_type: CutType) -> &mut Self
pub fn cut_paper(&mut self, cut_type: CutType) -> &mut Self
Append a command for cutting the paper totally (CutType::TotalCut
) or partially (CutType::PartialCut
).
§Examples
printer.cut_paper(CutType::TotalCut);
Examples found in repository?
3fn main() {
4 // Replace /dev/null with actual device node when the printer is connected
5 // e.g.: /dev/usb/lp0
6 let mut printer = CustomPrinter::new("/dev/null").unwrap();
7 printer
8 .bit_image(
9 "tests/data/Thermal_Test_Image.png",
10 BitImageMode::Dots24DoubleDensity,
11 )
12 .unwrap()
13 .cut_paper(CutType::TotalCut)
14 .run()
15 .unwrap();
16}
Sourcepub fn run(&mut self) -> Result<&mut Self, Error>
pub fn run(&mut self) -> Result<&mut Self, Error>
Run the constructed commands in the CustomPrinter
.
The constructed commands will be cleared if the printing succeeds.
NOTE: Because writing to the device node may fail, so the return Self is wrapped in a Result
and needs to be unwrapped before concatenating with other constructing functions.
§Examples
printer
.bit_image(
"tests/data/Thermal_Test_Image.png",
BitImageMode::Dots24DoubleDensity
)
.unwrap()
.cut_paper(CutType::TotalCut)
.run()
.unwrap();
Examples found in repository?
3fn main() {
4 // Replace /dev/null with actual device node when the printer is connected
5 // e.g.: /dev/usb/lp0
6 let mut printer = CustomPrinter::new("/dev/null").unwrap();
7 printer
8 .bit_image(
9 "tests/data/Thermal_Test_Image.png",
10 BitImageMode::Dots24DoubleDensity,
11 )
12 .unwrap()
13 .cut_paper(CutType::TotalCut)
14 .run()
15 .unwrap();
16}
Auto Trait Implementations§
impl Freeze for CustomPrinter
impl RefUnwindSafe for CustomPrinter
impl Send for CustomPrinter
impl Sync for CustomPrinter
impl Unpin for CustomPrinter
impl UnwindSafe for CustomPrinter
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
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>
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>
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