@@ -262,6 +262,8 @@ pub struct RpcDescription {
262262 pub ( crate ) needs_client : bool ,
263263 /// Optional prefix for RPC namespace.
264264 pub ( crate ) namespace : Option < String > ,
265+ /// Optional separator between namespace and method name. Defaults to `_`.
266+ pub ( crate ) namespace_separator : Option < String > ,
265267 /// Trait definition in which all the attributes were stripped.
266268 pub ( crate ) trait_def : syn:: ItemTrait ,
267269 /// List of RPC methods defined in the trait.
@@ -276,12 +278,20 @@ pub struct RpcDescription {
276278
277279impl RpcDescription {
278280 pub fn from_item ( attr : Attribute , mut item : syn:: ItemTrait ) -> syn:: Result < Self > {
279- let [ client, server, namespace, client_bounds, server_bounds] =
280- AttributeMeta :: parse ( attr) ?. retain ( [ "client" , "server" , "namespace" , "client_bounds" , "server_bounds" ] ) ?;
281+ let [ client, server, namespace, namespace_separator, client_bounds, server_bounds] =
282+ AttributeMeta :: parse ( attr) ?. retain ( [
283+ "client" ,
284+ "server" ,
285+ "namespace" ,
286+ "namespace_separator" ,
287+ "client_bounds" ,
288+ "server_bounds" ,
289+ ] ) ?;
281290
282291 let needs_server = optional ( server, Argument :: flag) ?. is_some ( ) ;
283292 let needs_client = optional ( client, Argument :: flag) ?. is_some ( ) ;
284293 let namespace = optional ( namespace, Argument :: string) ?;
294+ let namespace_separator = optional ( namespace_separator, Argument :: string) ?;
285295 let client_bounds = optional ( client_bounds, Argument :: group) ?;
286296 let server_bounds = optional ( server_bounds, Argument :: group) ?;
287297 if !needs_server && !needs_client {
@@ -368,6 +378,7 @@ impl RpcDescription {
368378 needs_server,
369379 needs_client,
370380 namespace,
381+ namespace_separator,
371382 trait_def : item,
372383 methods,
373384 subscriptions,
@@ -400,12 +411,18 @@ impl RpcDescription {
400411 quote ! { #jsonrpsee:: #item }
401412 }
402413
403- /// Based on the namespace, renders the full name of the RPC method/subscription.
414+ /// Based on the namespace and separator , renders the full name of the RPC method/subscription.
404415 /// Examples:
405- /// For namespace `foo` and method `makeSpam`, result will be `foo_makeSpam`.
406- /// For no namespace and method `makeSpam` it will be just `makeSpam`.
416+ /// For namespace `foo`, method `makeSpam`, and separator `_`, result will be `foo_makeSpam`.
417+ /// For separator `.`, result will be `foo.makeSpam`.
418+ /// For no namespace, returns just `makeSpam`.
407419 pub ( crate ) fn rpc_identifier < ' a > ( & self , method : & ' a str ) -> Cow < ' a , str > {
408- if let Some ( ns) = & self . namespace { format ! ( "{ns}_{method}" ) . into ( ) } else { Cow :: Borrowed ( method) }
420+ if let Some ( ns) = & self . namespace {
421+ let sep = self . namespace_separator . as_deref ( ) . unwrap_or ( "_" ) ;
422+ format ! ( "{ns}{sep}{method}" ) . into ( )
423+ } else {
424+ Cow :: Borrowed ( method)
425+ }
409426 }
410427}
411428
0 commit comments