@@ -83,7 +83,7 @@ use channel::{mpsc, oneshot};
8383///
8484/// This attribute macro may be applied to an enum where each variant represents
8585/// a different RPC request type. Each variant of the enum must contain a single unnamed field
86- /// of a distinct type, otherwise compilation fails .
86+ /// of a distinct type (unless the `wrap` attribute is used on a variant, see below) .
8787///
8888/// Basic usage example:
8989/// ```
@@ -148,9 +148,32 @@ use channel::{mpsc, oneshot};
148148/// * `rx = OtherType` *(optional)*: Set the kind of channel for receiving updates from the client at the server.
149149/// Must be a `Receiver` type from the [`crate::channel`] module. If `rx` is not set,
150150/// it defaults to [`crate::channel::none::NoReceiver`].
151+ /// * `wrap = TypeName` *(optional)*: If set, a struct `TypeName` will be generated from the variant's fields, and the variant
152+ /// will be changed to have a single, unnamed field of `TypeName`.
151153///
152154/// ## Examples
153155///
156+ /// With `wrap`:
157+ /// ```
158+ /// use serde::{Serialize, Deserialize};
159+ /// use irpc::{rpc_requests, channel::{oneshot, mpsc}, Client};
160+ ///
161+ /// #[rpc_requests(message = StoreMessage)]
162+ /// #[derive(Debug, Serialize, Deserialize)]
163+ /// enum StoreProtocol {
164+ /// #[rpc(wrap=GetRequest, tx=oneshot::Sender<String>)]
165+ /// Get(String),
166+ /// #[rpc(wrap=SetRequest, tx=oneshot::Sender<()>)]
167+ /// Set { key: String, value: String }
168+ /// }
169+ ///
170+ /// async fn client_usage(client: Client<StoreProtocol>) -> anyhow::Result<()> {
171+ /// client.rpc(SetRequest { key: "foo".to_string(), value: "bar".to_string() }).await?;
172+ /// let value = client.rpc(GetRequest("foo".to_string())).await?;
173+ /// Ok(())
174+ /// }
175+ /// ```
176+ ///
154177/// With type aliases:
155178/// ```no_compile
156179/// #[rpc_requests(message = ComputeMessage, alias = "Msg")]
0 commit comments