Skip to content

Commit 36e75a4

Browse files
authored
Merge pull request #476 from godot-rust/qol/rename-virtual-traits
Rename all virtual traits: `*Virtual` -> `I*`
2 parents a81fc41 + 420bb78 commit 36e75a4

File tree

17 files changed

+62
-61
lines changed

17 files changed

+62
-61
lines changed

examples/dodge-the-creeps/rust/src/hud.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use godot::engine::{Button, CanvasLayer, CanvasLayerVirtual, Label, Timer};
1+
use godot::engine::{Button, CanvasLayer, ICanvasLayer, Label, Timer};
22
use godot::prelude::*;
33

44
#[derive(GodotClass)]
@@ -61,7 +61,7 @@ impl Hud {
6161
}
6262

6363
#[godot_api]
64-
impl CanvasLayerVirtual for Hud {
64+
impl ICanvasLayer for Hud {
6565
fn init(base: Base<Self::Base>) -> Self {
6666
Self { base }
6767
}

examples/dodge-the-creeps/rust/src/main_scene.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl Main {
121121
}
122122

123123
#[godot_api]
124-
impl NodeVirtual for Main {
124+
impl INode for Main {
125125
fn init(base: Base<Node>) -> Self {
126126
Main {
127127
mob_scene: PackedScene::new(),

examples/dodge-the-creeps/rust/src/mob.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use godot::engine::{AnimatedSprite2D, RigidBody2D, RigidBody2DVirtual};
1+
use godot::engine::{AnimatedSprite2D, IRigidBody2D, RigidBody2D};
22
use godot::prelude::*;
33
use rand::seq::SliceRandom;
44

@@ -26,7 +26,7 @@ impl Mob {
2626
}
2727

2828
#[godot_api]
29-
impl RigidBody2DVirtual for Mob {
29+
impl IRigidBody2D for Mob {
3030
fn init(base: Base<RigidBody2D>) -> Self {
3131
Mob {
3232
min_speed: 150.0,

examples/dodge-the-creeps/rust/src/player.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use godot::engine::{AnimatedSprite2D, Area2D, Area2DVirtual, CollisionShape2D, PhysicsBody2D};
1+
use godot::engine::{AnimatedSprite2D, Area2D, CollisionShape2D, IArea2D, PhysicsBody2D};
22
use godot::prelude::*;
33

44
#[derive(GodotClass)]
@@ -42,7 +42,7 @@ impl Player {
4242
}
4343

4444
#[godot_api]
45-
impl Area2DVirtual for Player {
45+
impl IArea2D for Player {
4646
fn init(base: Base<Area2D>) -> Self {
4747
Player {
4848
speed: 400.0,

godot-codegen/src/class_generator.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,16 @@ fn make_class_doc(
391391
godot_ty.to_ascii_lowercase()
392392
);
393393

394+
let trait_name = class_name.virtual_trait_name();
395+
394396
format!(
395397
"Godot class `{godot_ty}.`\n\n\
396398
\
397399
{inherits_line}\n\n\
398400
\
399401
Related symbols:\n\n\
400402
{sidecar_line}\
401-
* [`{rust_ty}Virtual`][crate::engine::{rust_ty}Virtual]: virtual methods\n\
403+
* [`{trait_name}`][crate::engine::{trait_name}]: virtual methods\n\
402404
{notify_line}\
403405
\n\n\
404406
See also [Godot docs for `{godot_ty}`]({online_link}).\n\n",

godot-codegen/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl TyName {
250250
}
251251

252252
fn virtual_trait_name(&self) -> String {
253-
format!("{}Virtual", self.rust_ty)
253+
format!("I{}", self.rust_ty)
254254
}
255255
}
256256

godot-core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub use registry::*;
2323
///
2424
/// This module contains the following symbols:
2525
/// * Classes: `CanvasItem`, etc.
26-
/// * Virtual traits: `CanvasItemVirtual`, etc.
26+
/// * Virtual traits: `ICanvasItem`, etc.
2727
/// * Enum/flag modules: `canvas_item`, etc.
2828
///
2929
/// Noteworthy sub-modules are:

godot-core/src/registry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ fn fill_class_info(component: PluginComponent, c: &mut ClassRegistrationInfo) {
353353
} => {
354354
c.user_register_fn = user_register_fn;
355355

356-
// following unwraps of fill_into shouldn't panic since rustc will error if there's
357-
// multiple `impl {Class}Virtual for Thing` definitions
356+
// The following unwraps of fill_into() shouldn't panic, since rustc will error if there are
357+
// multiple `impl I{Class} for Thing` definitions.
358358

359359
fill_into(&mut c.godot_params.create_instance_func, user_create_fn).unwrap();
360360

godot-macros/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,11 @@ pub fn derive_godot_class(input: TokenStream) -> TokenStream {
376376
///
377377
/// // 2) trait impl block: implement Godot-specific APIs
378378
/// #[godot_api]
379-
/// impl NodeVirtual for MyClass { /* ... */ }
379+
/// impl INode for MyClass { /* ... */ }
380380
/// ```
381381
///
382-
/// The second case works by implementing the corresponding trait `<Base>Virtual` for the base class of your class
383-
/// (for example `RefCountedVirtual` or `Node3DVirtual`). Then, you can add functionality such as:
382+
/// The second case works by implementing the corresponding trait `I<Base>` for the base class of your class
383+
/// (for example `IRefCounted` or `INode3D`). Then, you can add functionality such as:
384384
/// * `init` constructors
385385
/// * lifecycle methods like `ready` or `process`
386386
/// * `on_notification` method
@@ -408,7 +408,7 @@ pub fn derive_godot_class(input: TokenStream) -> TokenStream {
408408
/// }
409409
///
410410
/// #[godot_api]
411-
/// impl RefCountedVirtual for MyStruct {
411+
/// impl IRefCounted for MyStruct {
412412
/// fn init(_base: Base<RefCounted>) -> Self {
413413
/// MyStruct
414414
/// }
@@ -431,7 +431,7 @@ pub fn derive_godot_class(input: TokenStream) -> TokenStream {
431431
/// }
432432
///
433433
/// #[godot_api]
434-
/// impl NodeVirtual for MyNode {
434+
/// impl INode for MyNode {
435435
/// fn ready(&mut self) {
436436
/// godot_print!("Hello World!");
437437
/// }

godot-macros/src/util/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ pub(crate) fn validate_trait_impl_virtual(
173173
// Validate trait
174174
if !typename
175175
.as_ref()
176-
.map_or(false, |seg| seg.ident.to_string().ends_with("Virtual"))
176+
.map_or(false, |seg| seg.ident.to_string().starts_with('I'))
177177
{
178178
return bail!(
179179
original_impl,
180-
"#[{attr}] for trait impls requires a virtual method trait (trait name should end in 'Virtual')",
180+
"#[{attr}] for trait impls requires a virtual method trait (trait name should start with 'I')",
181181
);
182182
}
183183

0 commit comments

Comments
 (0)