| Name | Message | Date |
|---|---|---|
| 📄 main.rs | 1 month ago | |
| 📄 proto.rs | 1 month ago |
📄
src/main.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
mod proto; use tonic::{Request, Response, Status, transport::Server}; use proto::receipt_printer_server::{ReceiptPrinter, ReceiptPrinterServer}; use proto::{PrintRequest, PrintResponse}; #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let addr = "[::1]:50051".parse()?; let receipt_printer_service = ReceiptPrinterService::default(); Server::builder() .add_service(ReceiptPrinterServer::new(receipt_printer_service)) .serve(addr) .await?; Ok(()) } #[derive(Debug, Default)] pub struct ReceiptPrinterService {} #[tonic::async_trait] impl ReceiptPrinter for ReceiptPrinterService { async fn print( &self, request: Request<PrintRequest>, // Accept request of type PrintRequest ) -> Result<Response<PrintResponse>, Status> { // Return an instance of type PrintResponse println!("Got a request: {:?}", request); let reply = PrintResponse {}; Ok(Response::new(reply)) } }