| Name | Message | Date |
|---|---|---|
| 📁 receipt_printer | 1 month ago | |
| 📁 typst_renderer | 1 month ago | |
| 📄 main.rs | 1 month ago | |
| 📄 proto.rs | - | |
| 📄 receipt_printer_service.rs | 1 month ago |
📄
src/receipt_printer_service.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use tonic::{Request, Response, Status}; use crate::proto::print_request::Content; use crate::proto::receipt_printer_server; use crate::proto::{PrintRequest, PrintResponse, TypstContent}; use crate::receipt_printer::ReceiptPrinter; use crate::typst_renderer::render_typst_receipt; pub struct ReceiptPrinterService { receipt_printer: ReceiptPrinter, } impl ReceiptPrinterService { pub fn new(receipt_printer: ReceiptPrinter) -> Self { Self { receipt_printer } } } #[tonic::async_trait] impl receipt_printer_server::ReceiptPrinter for ReceiptPrinterService { async fn print( &self, request: Request<PrintRequest>, ) -> Result<Response<PrintResponse>, Status> { let Some(Content::Typst(TypstContent { content: Some(content), })) = &request.get_ref().content else { return Err(Status::invalid_argument("No Typst content received")); }; let image = match render_typst_receipt(content) { Ok(image) => image, Err(error) => { return Err(Status::internal(format!( "Error rendering receipt: {error}" ))); } }; if let Err(error) = self.receipt_printer.print_image(image.into()).await { return Err(Status::internal(format!("Error when printing: {error}"))); } Ok(Response::new(PrintResponse::default())) } }