Skip to content

Commit dd21dfd

Browse files
committed
Document #[rpc] in #[godot_api] macro
1 parent 2406372 commit dd21dfd

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

godot-core/src/registry/rpc_config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ use crate::{arg_into_ref, dict};
1414

1515
/// Configuration for a remote procedure call, used with `#[rpc(config = ...)]`.
1616
///
17-
/// See [Godot documentation](https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html#remote-procedure-calls).
17+
/// Check documentation of the [`#[rpc]` attribute](attr.godot_api.html#rpc-attributes) for usage.
18+
///
19+
/// See also [Godot `@rpc` keyword](https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html#remote-procedure-calls).
1820
#[derive(Copy, Clone, Debug)]
1921
pub struct RpcConfig {
2022
pub rpc_mode: RpcMode,

godot-macros/src/lib.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,58 @@ pub fn derive_godot_class(input: TokenStream) -> TokenStream {
681681
///
682682
/// You can use the `#[rpc]` attribute to let your functions act as remote procedure calls (RPCs) in Godot. This is the Rust equivalent of
683683
/// GDScript's [`@rpc` annotation](https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html#remote-procedure-calls).
684+
/// `#[rpc]` is only supported for classes inheriting `Node`, and they need to declare a `Base<T>` field.
684685
///
686+
/// The syntax follows GDScript'a `@rpc`. You can optionally specify up to four keys; omitted ones use their default value.
687+
/// Here's an overview:
685688
///
689+
/// | Setting | Type | Possible values (first is default) |
690+
/// |---------------|------------------|----------------------------------------------------|
691+
/// | RPC mode | [`RpcMode`] | **`authority`**, `any_peer` |
692+
/// | Sync | `bool` | **`call_remote`**, `call_local` |
693+
/// | Transfer mode | [`TransferMode`] | **`unreliable`**, `unreliable_ordered`, `reliable` |
694+
/// | Channel | `u32` | any |
695+
///
696+
/// You can also use `#[rpc(config = value)]`, with `value` being a constant of type [`RpcConfig`] in scope. This can be useful to reuse
697+
/// configurations across multiple RPCs.
698+
///
699+
/// `#[rpc]` implies `#[func]`. You can use both attributes together, if you need to configure other `#[func]`-specific keys.
700+
///
701+
/// For example, the following method declarations are all equivalent:
702+
/// ```
703+
/// use godot::classes::multiplayer_api::RpcMode;
704+
/// use godot::classes::multiplayer_peer::TransferMode;
705+
/// use godot::prelude::*;
706+
/// use godot::register::RpcConfig;
707+
///
708+
/// # #[derive(GodotClass)]
709+
/// # #[class(no_init, base=Node)]
710+
/// # struct MyStruct {
711+
/// # base: Base<Node>,
712+
/// # }
713+
/// #[godot_api]
714+
/// impl MyStruct {
715+
/// #[rpc(unreliable_ordered, channel = 2)]
716+
/// fn with_defaults(&mut self) {}
717+
///
718+
/// #[rpc(authority, unreliable_ordered, call_remote, channel = 2)]
719+
/// fn explicit(&mut self) {}
720+
///
721+
/// #[rpc(config = MY_RPC_CONFIG)]
722+
/// fn external_config(&mut self) {}
723+
/// }
724+
///
725+
/// const MY_RPC_CONFIG: RpcConfig = RpcConfig {
726+
/// transfer_mode: TransferMode::UNRELIABLE_ORDERED,
727+
/// channel: 2,
728+
/// ..Default::default()
729+
/// };
730+
/// ```
731+
///
732+
// Note: for some reason, the intra-doc links don't work here, despite dev-dependency on godot.
733+
/// [`RpcMode`]: ../classes/multiplayer_api/struct.RpcMode.html
734+
/// [`TransferMode`]: ../classes/multiplayer_peer/struct.TransferMode.html
735+
/// [`RpcConfig`]: ../register/struct.RpcConfig.html
686736
///
687737
/// # Constants and signals
688738
///

0 commit comments

Comments
 (0)