Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[proc macros]: only generate unsub method if not provided #702

Merged
merged 9 commits into from
Feb 18, 2022
10 changes: 7 additions & 3 deletions proc-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ pub(crate) mod visitor;
///
/// - `name` (mandatory): name of the RPC method. Does not have to be the same as the Rust method name.
/// - `aliases`: list of name aliases for the RPC method as a comma separated string.
/// The aliases are kept outside namespace, so you need add that if you want aliases in the current
/// namespace.
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
/// - `blocking`: when set method execution will always spawn on a dedicated thread. Only usable with non-`async` methods.
/// - `param_kind`: kind of structure to use for parameter passing. Can be "array" or "map", defaults to "array".
///
Expand All @@ -179,9 +181,11 @@ pub(crate) mod visitor;
/// **Arguments:**
///
/// - `name` (mandatory): name of the RPC method. Does not have to be the same as the Rust method name.
/// - `unsubscribe` (optional): name of the RPC method used to unsubscribe from the subscription. Must not be the same as `name`.
/// - `aliases` (optional): aliases for `name`.
/// - `unsubscribe_aliases` (optional): aliases for `unsubscribe`.
/// - `unsubscribe` (optional): name of the RPC method to unsubscribe from the subscription. Must not be the same as `name`.
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
/// This is generated for you if the subscription name starts with `subscribe`-
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
/// - `aliases` (optional): aliases for `name`. The aliases are kept outside namespace,
/// so you need add that if you want aliases in the current namespace.
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
/// - `unsubscribe_aliases` (optional): Similar to `aliases` but for `unsubscribe`.
/// - `item` (mandatory): type of items yielded by the subscription. Note that it must be the type, not string.
/// - `param_kind`: kind of structure to use for parameter passing. Can be "array" or "map", defaults to "array".
///
Expand Down
2 changes: 1 addition & 1 deletion proc-macros/src/rpc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl RpcSubscription {
let unsubscribe = match parse_subscribe(unsubscribe)? {
Some(unsub) => unsub,
None => build_unsubscribe_method(&name).expect(
format!("Could not generate the unsubscribe method with name '{name}'. You need to provide the name manually using the `unsubscribe` attribute in your RPC API definition", name),
&format!("Could not generate the unsubscribe method with name '{}'. You need to provide the name manually using the `unsubscribe` attribute in your RPC API definition", name),
),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use jsonrpsee::{core::RpcResult, proc_macros::rpc};

#[rpc(client, server, namespace = "myapi")]
pub trait Rpc {
/// Alias doesn't use the namespace so not duplicated.
/// Aliases doesn't use the namespace.
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
/// Thus, this will generate `myapi_getTemp` and `getTemp`.
#[method(name = "getTemp", aliases = ["getTemp"])]
async fn async_method(&self, param_a: u8, param_b: String) -> RpcResult<u16>;

Expand Down