-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: alias attribute for proc macros (#442)
* feat: alias attribute for proc macros * implement David's suggested no more unsub field * keep aliases outside namespace * revert example * fix build * Update proc-macros/src/attributes.rs Co-authored-by: David <dvdplm@gmail.com> * grumbles: alias -> aliases * grumbles v2: alias -> aliases Co-authored-by: David <dvdplm@gmail.com>
- Loading branch information
Showing
29 changed files
with
177 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
proc-macros/tests/ui/correct/alias_doesnt_use_namespace.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use jsonrpsee::{proc_macros::rpc, types::JsonRpcResult}; | ||
|
||
#[rpc(client, server, namespace = "myapi")] | ||
pub trait Rpc { | ||
/// Alias doesn't use the namespace so not duplicated. | ||
#[method(name = "getTemp", aliases = "getTemp")] | ||
async fn async_method(&self, param_a: u8, param_b: String) -> JsonRpcResult<u16>; | ||
|
||
#[subscription(name = "getFood", item = String, aliases = "getFood", unsubscribe_aliases = "unsubscribegetFood")] | ||
fn sub(&self); | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
proc-macros/tests/ui/incorrect/method/method_unexpected_field.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use jsonrpsee::proc_macros::rpc; | ||
|
||
#[rpc(client, server)] | ||
pub trait DuplicatedAlias { | ||
#[method(name = "foo", aliases = "foo_dup, foo_dup")] | ||
async fn async_method(&self) -> jsonrpsee::types::JsonRpcResult<u8>; | ||
} | ||
|
||
fn main() {} |
5 changes: 5 additions & 0 deletions
5
proc-macros/tests/ui/incorrect/rpc/rpc_conflicting_alias.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: "foo_dup" is already defined | ||
--> $DIR/rpc_conflicting_alias.rs:6:11 | ||
| | ||
6 | async fn async_method(&self) -> jsonrpsee::types::JsonRpcResult<u8>; | ||
| ^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
error: Subscription methods must not be `async` | ||
--> $DIR/sub_async.rs:6:2 | ||
| | ||
6 | / #[subscription(name = "sub", unsub = "unsub", item = u8)] | ||
6 | / #[subscription(name = "sub", item = u8)] | ||
7 | | async fn sub(&self); | ||
| |________________________^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use jsonrpsee::proc_macros::rpc; | ||
|
||
#[rpc(client, server)] | ||
pub trait DuplicatedSubAlias { | ||
#[subscription(name = "alias", item = String, aliases = "hello_is_goodbye", unsubscribe_aliases = "hello_is_goodbye")] | ||
fn async_method(&self); | ||
} | ||
|
||
fn main() {} |
5 changes: 5 additions & 0 deletions
5
proc-macros/tests/ui/incorrect/sub/sub_conflicting_alias.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: "hello_is_goodbye" is already defined | ||
--> $DIR/sub_conflicting_alias.rs:6:5 | ||
| | ||
6 | fn async_method(&self); | ||
| ^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.