Skip to content

Commit

Permalink
Follow-up changes to RpcConfig + #[cfg] + clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Sep 22, 2024
1 parent c4dd6b7 commit 2ae2995
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
3 changes: 1 addition & 2 deletions godot-core/src/meta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ mod godot_convert;
mod method_info;
mod property_info;
mod ref_arg;
// RpcConfig uses `MultiplayerPeer::TransferMode` and `MultiplayerApi::RpcMode`,
// which are only available when `codegen-full` is enabled.
// RpcConfig uses MultiplayerPeer::TransferMode and MultiplayerApi::RpcMode, which are only enabled in `codegen-full` feature.
#[cfg(feature = "codegen-full")]
mod rpc_config;
mod sealed;
Expand Down
12 changes: 7 additions & 5 deletions godot-core/src/meta/rpc_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use crate::classes::Node;
use crate::dict;
use crate::meta::ToGodot;

/// See [Godot documentation](https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html#remote-procedure-calls)
/// Configuration for a remote procedure call, typically used with `#[rpc(config = ...)]`.
///
/// See [Godot documentation](https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html#remote-procedure-calls).
#[derive(Copy, Clone, Debug)]
pub struct RpcConfig {
pub rpc_mode: RpcMode,
Expand All @@ -34,12 +36,12 @@ impl Default for RpcConfig {

impl RpcConfig {
/// Register `method` as a remote procedure call on `node`.
pub fn register(self, node: &mut Node, method: impl Into<StringName>) {
node.rpc_config(method.into(), &self.into_dictionary().to_variant());
pub fn configure_node(self, node: &mut Node, method_name: impl Into<StringName>) {
node.rpc_config(method_name.into(), &self.to_dictionary().to_variant());
}

/// Returns a [`Dictionary`] populated with the values required for a call to [`Node::rpc_config`].
pub fn into_dictionary(self) -> Dictionary {
/// Returns a [`Dictionary`] populated with the values required for a call to [`Node::rpc_config()`].
pub fn to_dictionary(&self) -> Dictionary {
dict! {
"rpc_mode": self.rpc_mode,
"transfer_mode": self.transfer_mode,
Expand Down
5 changes: 3 additions & 2 deletions godot-core/src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use crate::meta::trace;

use crate::global::godot_error;
use crate::meta::error::CallError;
use crate::meta::{CallContext, ClassName};
use crate::meta::CallContext;
use crate::sys;
use std::sync::{atomic, Arc, Mutex};
use sys::Global;
Expand Down Expand Up @@ -129,7 +129,8 @@ pub(crate) fn iterate_plugins(mut visitor: impl FnMut(&ClassPlugin)) {
sys::plugin_foreach!(__GODOT_PLUGIN_REGISTRY; visitor);
}

pub(crate) fn find_inherent_impl(class_name: ClassName) -> Option<InherentImpl> {
#[cfg(feature = "codegen-full")] // Remove if used in other scenarios.
pub(crate) fn find_inherent_impl(class_name: crate::meta::ClassName) -> Option<InherentImpl> {
// We do this manually instead of using `iterate_plugins()` because we want to break as soon as we find a match.
let plugins = __godot_rust_plugin___GODOT_PLUGIN_REGISTRY.lock().unwrap();

Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/registry/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl ClassRegistrationInfo {
// Note: when changing this match, make sure the array has sufficient size.
let index = match item {
PluginItem::Struct { .. } => 0,
PluginItem::InherentImpl(InherentImpl { .. }) => 1,
PluginItem::InherentImpl(_) => 1,
PluginItem::ITraitImpl { .. } => 2,
};

Expand Down
4 changes: 2 additions & 2 deletions godot-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ homepage = "https://godot-rust.github.io"
[features]
api-custom = ["godot-bindings/api-custom"]
docs = ["dep:markdown"]
codegen-full = []
codegen-full = ["godot/__codegen-full"]

[lib]
proc-macro = true
Expand All @@ -32,7 +32,7 @@ godot-bindings = { path = "../godot-bindings", version = "=0.1.3" } # emit_godot

# Reverse dev dependencies so doctests can use `godot::` prefix.
[dev-dependencies]
godot = { path = "../godot", default-features = false, features = ["__codegen-full"] }
godot = { path = "../godot", default-features = false}

# https://docs.rs/about/metadata
[package.metadata.docs.rs]
Expand Down
2 changes: 1 addition & 1 deletion godot-macros/src/class/data_models/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ fn make_rpc_registration(func_def: &FuncDefinition) -> Option<TokenStream> {
let registration = quote! {
{
#create_struct
args.register(node, #method_name_str)
args.configure_node(node, #method_name_str)
}
};

Expand Down

0 comments on commit 2ae2995

Please sign in to comment.