|
13 | 13 | //! # Example |
14 | 14 | //! ``` |
15 | 15 | //! # async fn example() -> anyhow::Result<()> { |
16 | | -//! use quic_rpc::{message::RpcMsg, Service, RpcClient, RpcServer}; |
17 | | -//! use serde::{Serialize, Deserialize}; |
18 | 16 | //! use derive_more::{From, TryInto}; |
| 17 | +//! use quic_rpc::{message::RpcMsg, RpcClient, RpcServer, Service}; |
| 18 | +//! use serde::{Deserialize, Serialize}; |
19 | 19 | //! |
20 | 20 | //! // Define your messages |
21 | 21 | //! #[derive(Debug, Serialize, Deserialize)] |
|
39 | 39 | //! } |
40 | 40 | //! |
41 | 41 | //! impl Service for PingService { |
42 | | -//! type Req = PingRequest; |
43 | | -//! type Res = PingResponse; |
| 42 | +//! type Req = PingRequest; |
| 43 | +//! type Res = PingResponse; |
44 | 44 | //! } |
45 | 45 | //! |
46 | 46 | //! // Define interaction patterns for each request type |
47 | 47 | //! impl RpcMsg<PingService> for Ping { |
48 | | -//! type Response = Pong; |
| 48 | +//! type Response = Pong; |
49 | 49 | //! } |
50 | 50 | //! |
51 | 51 | //! // create a transport channel, here a memory channel for testing |
52 | 52 | //! let (server, client) = quic_rpc::transport::flume::channel(1); |
53 | 53 | //! |
54 | 54 | //! // client side |
55 | 55 | //! // create the rpc client given the channel and the service type |
56 | | -//! let mut client = RpcClient::<PingService,_>::new(client); |
| 56 | +//! let mut client = RpcClient::<PingService, _>::new(client); |
57 | 57 | //! |
58 | 58 | //! // call the service |
59 | 59 | //! let res = client.rpc(Ping).await?; |
|
64 | 64 | //! |
65 | 65 | //! let handler = Handler; |
66 | 66 | //! loop { |
67 | | -//! // accept connections |
68 | | -//! let (msg, chan) = server.accept().await?.read_first().await?; |
69 | | -//! // dispatch the message to the appropriate handler |
70 | | -//! match msg { |
71 | | -//! PingRequest::Ping(ping) => chan.rpc(ping, handler, Handler::ping).await?, |
72 | | -//! } |
| 67 | +//! // accept connections |
| 68 | +//! let (msg, chan) = server.accept().await?.read_first().await?; |
| 69 | +//! // dispatch the message to the appropriate handler |
| 70 | +//! match msg { |
| 71 | +//! PingRequest::Ping(ping) => chan.rpc(ping, handler, Handler::ping).await?, |
| 72 | +//! } |
73 | 73 | //! } |
74 | 74 | //! |
75 | 75 | //! // the handler. For a more complex example, this would contain any state |
|
78 | 78 | //! struct Handler; |
79 | 79 | //! |
80 | 80 | //! impl Handler { |
81 | | -//! // the handle fn for a Ping request. |
| 81 | +//! // the handle fn for a Ping request. |
82 | 82 | //! |
83 | | -//! // The return type is the response type for the service. |
84 | | -//! // Note that this must take self by value, not by reference. |
85 | | -//! async fn ping(self, _req: Ping) -> Pong { |
86 | | -//! Pong |
87 | | -//! } |
| 83 | +//! // The return type is the response type for the service. |
| 84 | +//! // Note that this must take self by value, not by reference. |
| 85 | +//! async fn ping(self, _req: Ping) -> Pong { |
| 86 | +//! Pong |
| 87 | +//! } |
88 | 88 | //! } |
89 | 89 | //! # Ok(()) |
90 | 90 | //! # } |
91 | 91 | //! ``` |
92 | 92 | #![deny(missing_docs)] |
93 | 93 | #![deny(rustdoc::broken_intra_doc_links)] |
94 | | -use serde::{de::DeserializeOwned, Serialize}; |
95 | 94 | use std::fmt::{Debug, Display}; |
| 95 | + |
| 96 | +use serde::{de::DeserializeOwned, Serialize}; |
96 | 97 | pub mod client; |
97 | 98 | pub mod message; |
98 | 99 | pub mod server; |
|
0 commit comments