Skip to content

Commit 9c34db8

Browse files
committed
docs
1 parent c9c2573 commit 9c34db8

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/lib.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ use std::{fmt::Debug, future::Future, io, marker::PhantomData, ops::Deref, resul
8282
///
8383
/// This attribute macro may be applied to an enum where each variant represents
8484
/// a different RPC request type. Each variant of the enum must contain a single unnamed field
85-
/// of a distinct type, otherwise compilation fails.
85+
/// of a distinct type (unless the `wrap` attribute is used on a variant, see below).
8686
///
8787
/// Basic usage example:
8888
/// ```
@@ -147,9 +147,32 @@ use std::{fmt::Debug, future::Future, io, marker::PhantomData, ops::Deref, resul
147147
/// * `rx = OtherType` *(optional)*: Set the kind of channel for receiving updates from the client at the server.
148148
/// Must be a `Receiver` type from the [`crate::channel`] module. If `rx` is not set,
149149
/// it defaults to [`crate::channel::none::NoReceiver`].
150+
/// * `wrap = TypeName` *(optional)*: If set, a struct `TypeName` will be generated from the variant's fields, and the variant
151+
/// will be changed to have a single, unnamed field of `TypeName`.
150152
///
151153
/// ## Examples
152154
///
155+
/// With `wrap`:
156+
/// ```
157+
/// use serde::{Serialize, Deserialize};
158+
/// use irpc::{rpc_requests, channel::{oneshot, mpsc}, Client};
159+
///
160+
/// #[rpc_requests(message = StoreMessage)]
161+
/// #[derive(Debug, Serialize, Deserialize)]
162+
/// enum StoreProtocol {
163+
/// #[rpc(wrap=GetRequest, tx=oneshot::Sender<String>)]
164+
/// Get(String),
165+
/// #[rpc(wrap=SetRequest, tx=oneshot::Sender<()>)]
166+
/// Set { key: String, value: String }
167+
/// }
168+
///
169+
/// async fn client_usage(client: Client<StoreProtocol>) -> anyhow::Result<()> {
170+
/// client.rpc(SetRequest { key: "foo".to_string(), value: "bar".to_string() }).await?;
171+
/// let value = client.rpc(GetRequest("foo".to_string())).await?;
172+
/// Ok(())
173+
/// }
174+
/// ```
175+
///
153176
/// With type aliases:
154177
/// ```no_compile
155178
/// #[rpc_requests(message = ComputeMessage, alias = "Msg")]

0 commit comments

Comments
 (0)