Skip to content

Commit 7cf2c4e

Browse files
committed
Signal + test small cleanup
1 parent 3c743e4 commit 7cf2c4e

File tree

4 files changed

+83
-129
lines changed

4 files changed

+83
-129
lines changed

godot-macros/src/class/data_models/inherent_impl.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
*/
7+
78
use crate::class::{
89
into_signature_info, make_constant_registration, make_method_registration,
910
make_signal_registrations, ConstDefinition, FuncDefinition, RpcAttr, RpcMode, SignalDefinition,
@@ -66,7 +67,7 @@ struct FuncAttr {
6667

6768
pub struct InherentImplAttr {
6869
/// For implementation reasons, there can be a single 'primary' impl block and 0 or more 'secondary' impl blocks.
69-
/// For now this is controlled by a key in the the 'godot_api' attribute
70+
/// For now, this is controlled by a key in the 'godot_api' attribute.
7071
pub secondary: bool,
7172
}
7273

@@ -107,16 +108,13 @@ pub fn transform_inherent_impl(
107108

108109
let fill_storage = quote! {
109110
::godot::sys::plugin_execute_pre_main!({
110-
#method_storage_name.lock().unwrap().push(||{
111-
111+
#method_storage_name.lock().unwrap().push(|| {
112112
#( #method_registrations )*
113113
#( #signal_registrations )*
114-
115114
});
116-
#constants_storage_name.lock().unwrap().push(||{
117115

116+
#constants_storage_name.lock().unwrap().push(|| {
118117
#constant_registration
119-
120118
});
121119
});
122120
};
@@ -155,7 +153,6 @@ pub fn transform_inherent_impl(
155153
};
156154

157155
let class_registration = quote! {
158-
159156
::godot::sys::plugin_add!(__GODOT_PLUGIN_REGISTRY in #prv; #prv::ClassPlugin {
160157
class_name: #class_name_obj,
161158
item: #prv::PluginItem::InherentImpl(#prv::InherentImpl {
@@ -169,7 +166,6 @@ pub fn transform_inherent_impl(
169166
}),
170167
init_level: <#class_name as ::godot::obj::GodotClass>::INIT_LEVEL,
171168
});
172-
173169
};
174170

175171
let result = quote! {
@@ -182,7 +178,7 @@ pub fn transform_inherent_impl(
182178

183179
Ok(result)
184180
} else {
185-
// We are in a secondary `impl` block, so most of the work has already been done
181+
// We are in a secondary `impl` block, so most of the work has already been done,
186182
// and we just need to add our registration functions in the storage defined by the primary `impl` block.
187183

188184
let result = quote! {

itest/rust/src/builtin_tests/containers/callable_test.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
*/
7+
78
use godot::builtin::inner::InnerCallable;
89
use godot::builtin::{varray, Callable, GString, StringName, Variant};
910
use godot::classes::{Node2D, Object};
1011
use godot::meta::ToGodot;
1112
use godot::obj::{NewAlloc, NewGd};
1213
use godot::register::{godot_api, GodotClass};
13-
use std::fmt::{Display, Formatter};
1414
use std::hash::Hasher;
1515
use std::sync::atomic::{AtomicU32, Ordering};
1616

@@ -364,7 +364,7 @@ pub mod custom_callable {
364364
}
365365

366366
impl Hash for Adder {
367-
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
367+
fn hash<H: Hasher>(&self, state: &mut H) {
368368
let mut guard = self.tracker.lock().unwrap();
369369
guard.hash_counter += 1;
370370

@@ -378,7 +378,7 @@ pub mod custom_callable {
378378
}
379379
}
380380

381-
impl godot::builtin::RustCallable for Adder {
381+
impl RustCallable for Adder {
382382
fn invoke(&mut self, args: &[&Variant]) -> Result<Variant, ()> {
383383
for arg in args {
384384
self.sum += arg.to::<i32>();
@@ -410,6 +410,7 @@ pub mod custom_callable {
410410
tracker.lock().unwrap().hash_counter
411411
}
412412

413+
// Also used in signal_test.
413414
pub struct PanicCallable(pub Arc<AtomicU32>);
414415

415416
impl PartialEq for PanicCallable {
@@ -424,8 +425,8 @@ pub mod custom_callable {
424425
}
425426
}
426427

427-
impl Display for PanicCallable {
428-
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
428+
impl fmt::Display for PanicCallable {
429+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
429430
write!(f, "test")
430431
}
431432
}

0 commit comments

Comments
 (0)