diff --git a/godot-macros/src/lib.rs b/godot-macros/src/lib.rs index cb2e77f6e..51008f8a7 100644 --- a/godot-macros/src/lib.rs +++ b/godot-macros/src/lib.rs @@ -692,8 +692,8 @@ pub fn derive_godot_class(input: TokenStream) -> TokenStream { /// | Transfer mode | [`TransferMode`] | **`unreliable`**, `unreliable_ordered`, `reliable` | /// | Channel | `u32` | any | /// -/// You can also use `#[rpc(config = value)]`, with `value` being a constant of type [`RpcConfig`] in scope. This can be useful to reuse -/// configurations across multiple RPCs. +/// You can also use `#[rpc(config = value)]`, with `value` being an expression of type [`RpcConfig`] in scope, for example a `const` or the +/// call to a function. This can be useful to reuse configurations across multiple RPCs. /// /// `#[rpc]` implies `#[func]`. You can use both attributes together, if you need to configure other `#[func]`-specific keys. /// @@ -716,14 +716,26 @@ pub fn derive_godot_class(input: TokenStream) -> TokenStream { /// fn explicit(&mut self) {} /// /// #[rpc(config = MY_RPC_CONFIG)] -/// fn external_config(&mut self) {} +/// fn external_config_const(&mut self) {} +/// +/// #[rpc(config = my_rpc_provider())] +/// fn external_config_fn(&mut self) {} /// } /// /// const MY_RPC_CONFIG: RpcConfig = RpcConfig { +/// rpc_mode: RpcMode::AUTHORITY, /// transfer_mode: TransferMode::UNRELIABLE_ORDERED, +/// call_local: false, /// channel: 2, -/// ..Default::default() /// }; +/// +/// fn my_rpc_provider() -> RpcConfig { +/// RpcConfig { +/// transfer_mode: TransferMode::UNRELIABLE_ORDERED, +/// channel: 2, +/// ..Default::default() // only possible in fn, not in const. +/// } +/// } /// ``` /// // Note: for some reason, the intra-doc links don't work here, despite dev-dependency on godot. diff --git a/itest/rust/src/register_tests/rpc_test.rs b/itest/rust/src/register_tests/rpc_test.rs index d9b4522b3..35a1ecd3a 100644 --- a/itest/rust/src/register_tests/rpc_test.rs +++ b/itest/rust/src/register_tests/rpc_test.rs @@ -25,6 +25,14 @@ const CACHED_CFG: RpcConfig = RpcConfig { channel: 1, }; +fn provide_cfg() -> RpcConfig { + RpcConfig { + transfer_mode: TransferMode::RELIABLE, + channel: 1, + ..Default::default() + } +} + #[godot_api] impl RpcTest { #[rpc] @@ -66,7 +74,10 @@ impl RpcTest { pub fn args_func_gd_self(_this: Gd) {} #[rpc(config = CACHED_CFG)] - pub fn arg_config(&mut self) {} + pub fn arg_config_const(&mut self) {} + + #[rpc(config = provide_cfg())] + pub fn arg_config_fn(&mut self) {} } // ----------------------------------------------------------------------------------------------------------------------------------------------