Skip to content

Commit

Permalink
Use path instead of ident in dispatch_impl! (#73)
Browse files Browse the repository at this point in the history
This allows the `dispatch_impl!` macro to accept not only identifiers,
but also fully qualified paths which refer to either a list of
endpoints, incoming topics, or outgoing topics.
  • Loading branch information
Leandros authored Jan 4, 2025
1 parent 885fae4 commit 62d2fd0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 6 additions & 4 deletions source/postcard-rpc-test/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use postcard_rpc::{
host_client::{test_channels as client, HostClient},
server::{
impls::test_channels::{
dispatch_impl::{new_server, new_server_stoppable, spawn_fn, Settings, WireSpawnImpl, WireTxImpl},
dispatch_impl::{
new_server, new_server_stoppable, spawn_fn, Settings, WireSpawnImpl, WireTxImpl,
},
ChannelWireRx, ChannelWireSpawn, ChannelWireTx,
},
Dispatch, Sender, SpawnContext,
Expand Down Expand Up @@ -130,7 +132,7 @@ define_dispatch! {
context: TestContext;

endpoints: {
list: ENDPOINT_LIST;
list: crate::ENDPOINT_LIST;

| EndpointTy | kind | handler |
| ---------- | ---- | ------- |
Expand All @@ -140,7 +142,7 @@ define_dispatch! {
| BorrowEndpoint2 | blocking | test_borrowep_blocking2 |
};
topics_in: {
list: TOPICS_IN_LIST;
list: crate::TOPICS_IN_LIST;

| TopicTy | kind | handler |
| ---------- | ---- | ------- |
Expand Down Expand Up @@ -600,7 +602,7 @@ async fn end_to_end_stoppable() {
assert_eq!(resp.0, 42);
stopper.stop();
match timeout(Duration::from_millis(100), hdl).await {
Ok(Ok(())) => {},
Ok(Ok(())) => {}
Ok(Err(e)) => panic!("Server task panicked? {e:?}"),
Err(_) => panic!("Server task did not stop!"),
}
Expand Down
10 changes: 5 additions & 5 deletions source/postcard-rpc/src/server/dispatch_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,21 +225,21 @@ macro_rules! define_dispatch {
context: $context_ty:ty;

endpoints: {
list: $endpoint_list:ident;
list: $endpoint_list:path;

| EndpointTy | kind | handler |
| $(-)* | $(-)* | $(-)* |
$( | $endpoint:ty | $ep_flavor:tt | $ep_handler:ident | )*
$( | $endpoint:ty | $ep_flavor:tt | $ep_handler:ident | )*
};
topics_in: {
list: $topic_in_list:ident;
list: $topic_in_list:path;

| TopicTy | kind | handler |
| $(-)* | $(-)* | $(-)* |
$( | $topic_in:ty | $tp_flavor:tt | $tp_handler:ident | )*
$( | $topic_in:ty | $tp_flavor:tt | $tp_handler:ident | )*
};
topics_out: {
list: $topic_out_list:ident;
list: $topic_out_list:path;
};
) => {

Expand Down

0 comments on commit 62d2fd0

Please sign in to comment.