Skip to content

Commit 1fb77e2

Browse files
committed
WithChannels -> Request
1 parent e31cc67 commit 1fb77e2

File tree

8 files changed

+63
-64
lines changed

8 files changed

+63
-64
lines changed

examples/compute.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use irpc::{
1111
rpc::{listen, Handler},
1212
rpc_requests,
1313
util::{make_client_endpoint, make_server_endpoint},
14-
Client, LocalSender, RequestSender, Service, WithChannels,
14+
Client, LocalSender, Request, RequestSender, Service,
1515
};
1616
use n0_future::{
1717
stream::StreamExt,
@@ -99,7 +99,7 @@ impl ComputeActor {
9999
match msg {
100100
ComputeMessage::Sqr(sqr) => {
101101
trace!("sqr {:?}", sqr);
102-
let WithChannels {
102+
let Request {
103103
reply,
104104
message,
105105
span,
@@ -111,7 +111,7 @@ impl ComputeActor {
111111
}
112112
ComputeMessage::Sum(sum) => {
113113
trace!("sum {:?}", sum);
114-
let WithChannels {
114+
let Request {
115115
updates,
116116
reply,
117117
span,
@@ -127,7 +127,7 @@ impl ComputeActor {
127127
}
128128
ComputeMessage::Fibonacci(fib) => {
129129
trace!("fibonacci {:?}", fib);
130-
let WithChannels {
130+
let Request {
131131
reply,
132132
message,
133133
span,
@@ -146,7 +146,7 @@ impl ComputeActor {
146146
}
147147
ComputeMessage::Multiply(mult) => {
148148
trace!("multiply {:?}", mult);
149-
let WithChannels {
149+
let Request {
150150
updates,
151151
reply,
152152
message,

examples/derive.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use irpc::{
1010
rpc::Handler,
1111
rpc_requests,
1212
util::{make_client_endpoint, make_server_endpoint},
13-
Client, LocalSender, Service, WithChannels,
13+
Client, LocalSender, Request, Service,
1414
};
1515
// Import the macro
1616
use n0_future::task::{self, AbortOnDropHandle};
@@ -90,18 +90,18 @@ impl StorageActor {
9090
match msg {
9191
StorageMessage::Get(get) => {
9292
info!("get {:?}", get);
93-
let WithChannels { reply, message, .. } = get;
93+
let Request { reply, message, .. } = get;
9494
reply.send(self.state.get(&message.key).cloned()).await.ok();
9595
}
9696
StorageMessage::Set(set) => {
9797
info!("set {:?}", set);
98-
let WithChannels { reply, message, .. } = set;
98+
let Request { reply, message, .. } = set;
9999
self.state.insert(message.key, message.value);
100100
reply.send(()).await.ok();
101101
}
102102
StorageMessage::SetMany(set) => {
103103
info!("set-many {:?}", set);
104-
let WithChannels {
104+
let Request {
105105
mut updates, reply, ..
106106
} = set;
107107
let mut count = 0;
@@ -113,7 +113,7 @@ impl StorageActor {
113113
}
114114
StorageMessage::List(list) => {
115115
info!("list {:?}", list);
116-
let WithChannels { reply, .. } = list;
116+
let Request { reply, .. } = list;
117117
for (key, value) in &self.state {
118118
if reply.send(format!("{key}={value}")).await.is_err() {
119119
break;

examples/storage.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use irpc::{
99
channel::{mpsc, none::NoReceiver, oneshot},
1010
rpc::{listen, Handler},
1111
util::{make_client_endpoint, make_server_endpoint},
12-
Channels, Client, LocalSender, RequestSender, Service, WithChannels,
12+
Channels, Client, LocalSender, Request, RequestSender, Service,
1313
};
1414
use n0_future::task::{self, AbortOnDropHandle};
1515
use serde::{Deserialize, Serialize};
@@ -59,9 +59,9 @@ enum StorageProtocol {
5959

6060
#[derive(derive_more::From)]
6161
enum StorageMessage {
62-
Get(WithChannels<Get, StorageService>),
63-
Set(WithChannels<Set, StorageService>),
64-
List(WithChannels<List, StorageService>),
62+
Get(Request<Get, StorageService>),
63+
Set(Request<Set, StorageService>),
64+
List(Request<List, StorageService>),
6565
}
6666

6767
struct StorageActor {
@@ -93,18 +93,18 @@ impl StorageActor {
9393
match msg {
9494
StorageMessage::Get(get) => {
9595
info!("get {:?}", get);
96-
let WithChannels { reply, message, .. } = get;
96+
let Request { reply, message, .. } = get;
9797
reply.send(self.state.get(&message.key).cloned()).await.ok();
9898
}
9999
StorageMessage::Set(set) => {
100100
info!("set {:?}", set);
101-
let WithChannels { reply, message, .. } = set;
101+
let Request { reply, message, .. } = set;
102102
self.state.insert(message.key, message.value);
103103
reply.send(()).await.ok();
104104
}
105105
StorageMessage::List(list) => {
106106
info!("list {:?}", list);
107-
let WithChannels { reply, .. } = list;
107+
let Request { reply, .. } = list;
108108
for (key, value) in &self.state {
109109
if reply.send(format!("{key}={value}")).await.is_err() {
110110
break;

irpc-derive/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ fn generate_message_enum_from_impls(
9898
) -> TokenStream2 {
9999
let mut impls = quote! {};
100100

101-
// Generate From<WithChannels<T, Service>> implementations for each case with an rpc attribute
101+
// Generate From<Request<T, Service>> implementations for each case with an rpc attribute
102102
for (variant_name, message_type) in variants_with_attr {
103103
let impl_tokens = quote! {
104-
impl From<::irpc::WithChannels<#message_type, #service_name>> for #message_enum_name {
105-
fn from(value: ::irpc::WithChannels<#message_type, #service_name>) -> Self {
104+
impl From<::irpc::Request<#message_type, #service_name>> for #message_enum_name {
105+
fn from(value: ::irpc::Request<#message_type, #service_name>) -> Self {
106106
#message_enum_name::#variant_name(value)
107107
}
108108
}
@@ -117,7 +117,7 @@ fn generate_message_enum_from_impls(
117117
impls
118118
}
119119

120-
/// Generate type aliases for WithChannels<T, Service>
120+
/// Generate type aliases for Request<T, Service>
121121
fn generate_type_aliases(
122122
variants: &[(Ident, Type)],
123123
service_name: &Ident,
@@ -132,8 +132,8 @@ fn generate_type_aliases(
132132
let type_ident = Ident::new(&type_name, variant_name.span());
133133

134134
let alias = quote! {
135-
/// Type alias for WithChannels<#message_type, #service_name>
136-
pub type #type_ident = ::irpc::WithChannels<#message_type, #service_name>;
135+
/// Type alias for Request<#message_type, #service_name>
136+
pub type #type_ident = ::irpc::Request<#message_type, #service_name>;
137137
};
138138

139139
aliases = quote! {
@@ -153,8 +153,8 @@ fn generate_type_aliases(
153153
/// # Macro Arguments
154154
///
155155
/// * First positional argument (required): The service type that will handle these requests
156-
/// * `message` (optional): Generate an extended enum wrapping each type in `WithChannels<T, Service>`
157-
/// * `alias` (optional): Generate type aliases with the given suffix for each `WithChannels<T, Service>`
156+
/// * `message` (optional): Generate an extended enum wrapping each type in `Request<T, Service>`
157+
/// * `alias` (optional): Generate type aliases with the given suffix for each `Request<T, Service>`
158158
///
159159
/// # Variant Attributes
160160
///
@@ -194,9 +194,9 @@ fn generate_type_aliases(
194194
/// #[rpc_requests(ComputeService, alias = "Msg")]
195195
/// enum ComputeProtocol {
196196
/// #[rpc(reply=oneshot::Sender<u128>)]
197-
/// Sqr(Sqr), // Generates type SqrMsg = WithChannels<Sqr, ComputeService>
197+
/// Sqr(Sqr), // Generates type SqrMsg = Request<Sqr, ComputeService>
198198
/// #[rpc(reply=oneshot::Sender<i64>)]
199-
/// Sum(Sum), // Generates type SumMsg = WithChannels<Sum, ComputeService>
199+
/// Sum(Sum), // Generates type SumMsg = Request<Sum, ComputeService>
200200
/// }
201201
/// ```
202202
#[proc_macro_attribute]
@@ -302,7 +302,7 @@ pub fn rpc_requests(attr: TokenStream, item: TokenStream) -> TokenStream {
302302
.map(|(variant_name, message_type)| {
303303
quote! {
304304
#[allow(missing_docs)]
305-
#variant_name(::irpc::WithChannels<#message_type, #service_name>)
305+
#variant_name(::irpc::Request<#message_type, #service_name>)
306306
}
307307
})
308308
.collect::<Vec<_>>();
@@ -349,7 +349,7 @@ pub fn rpc_requests(attr: TokenStream, item: TokenStream) -> TokenStream {
349349
// From implementations for the original enum
350350
#original_from_impls
351351

352-
// Type aliases for WithChannels
352+
// Type aliases for Request
353353
#type_aliases
354354

355355
// Extended enum and its implementations

irpc-iroh/examples/auth.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ mod storage {
7373
};
7474
use irpc::{
7575
channel::{mpsc, oneshot},
76-
Client, Service, WithChannels,
76+
Client, Request, Service,
7777
};
7878
// Import the macro
7979
use irpc_derive::rpc_requests;
@@ -143,7 +143,7 @@ mod storage {
143143
let msg_with_channels = upcast_message(msg, request, reply);
144144
match msg_with_channels {
145145
StorageMessage::Auth(msg) => {
146-
let WithChannels { message, reply, .. } = msg;
146+
let Request { message, reply, .. } = msg;
147147
if authed {
148148
conn.close(1u32.into(), b"invalid message");
149149
break;
@@ -177,11 +177,11 @@ mod storage {
177177
reply: SendStream,
178178
) -> StorageMessage {
179179
match msg {
180-
StorageProtocol::Auth(msg) => WithChannels::from((msg, reply, request)).into(),
181-
StorageProtocol::Get(msg) => WithChannels::from((msg, reply, request)).into(),
182-
StorageProtocol::Set(msg) => WithChannels::from((msg, reply, request)).into(),
183-
StorageProtocol::SetMany(msg) => WithChannels::from((msg, reply, request)).into(),
184-
StorageProtocol::List(msg) => WithChannels::from((msg, reply, request)).into(),
180+
StorageProtocol::Auth(msg) => Request::from((msg, reply, request)).into(),
181+
StorageProtocol::Get(msg) => Request::from((msg, reply, request)).into(),
182+
StorageProtocol::Set(msg) => Request::from((msg, reply, request)).into(),
183+
StorageProtocol::SetMany(msg) => Request::from((msg, reply, request)).into(),
184+
StorageProtocol::List(msg) => Request::from((msg, reply, request)).into(),
185185
}
186186
}
187187

@@ -200,21 +200,21 @@ mod storage {
200200
StorageMessage::Auth(_) => unreachable!("handled in ProtocolHandler::accept"),
201201
StorageMessage::Get(get) => {
202202
info!("get {:?}", get);
203-
let WithChannels { reply, message, .. } = get;
203+
let Request { reply, message, .. } = get;
204204
let res = self.state.lock().unwrap().get(&message.key).cloned();
205205
reply.send(res).await.ok();
206206
}
207207
StorageMessage::Set(set) => {
208208
info!("set {:?}", set);
209-
let WithChannels { reply, message, .. } = set;
209+
let Request { reply, message, .. } = set;
210210
self.state
211211
.lock()
212212
.unwrap()
213213
.insert(message.key, message.value);
214214
reply.send(()).await.ok();
215215
}
216216
StorageMessage::SetMany(list) => {
217-
let WithChannels {
217+
let Request {
218218
reply, mut updates, ..
219219
} = list;
220220
let mut i = 0;
@@ -227,7 +227,7 @@ mod storage {
227227
}
228228
StorageMessage::List(list) => {
229229
info!("list {:?}", list);
230-
let WithChannels { reply, .. } = list;
230+
let Request { reply, .. } = list;
231231
let values = {
232232
let state = self.state.lock().unwrap();
233233
// TODO: use async lock to not clone here.

irpc-iroh/examples/derive.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ mod storage {
6262
use irpc::{
6363
channel::{mpsc, oneshot},
6464
rpc::Handler,
65-
rpc_requests, Client, LocalSender, Service, WithChannels,
65+
rpc_requests, Client, LocalSender, Request, Service,
6666
};
6767
// Import the macro
6868
use irpc_iroh::{IrohProtocol, IrohRemoteConnection};
@@ -130,18 +130,18 @@ mod storage {
130130
match msg {
131131
StorageMessage::Get(get) => {
132132
info!("get {:?}", get);
133-
let WithChannels { reply, message, .. } = get;
133+
let Request { reply, message, .. } = get;
134134
reply.send(self.state.get(&message.key).cloned()).await.ok();
135135
}
136136
StorageMessage::Set(set) => {
137137
info!("set {:?}", set);
138-
let WithChannels { reply, message, .. } = set;
138+
let Request { reply, message, .. } = set;
139139
self.state.insert(message.key, message.value);
140140
reply.send(()).await.ok();
141141
}
142142
StorageMessage::List(list) => {
143143
info!("list {:?}", list);
144-
let WithChannels { reply, .. } = list;
144+
let Request { reply, .. } = list;
145145
for (key, value) in &self.state {
146146
if reply.send(format!("{key}={value}")).await.is_err() {
147147
break;

0 commit comments

Comments
 (0)