From a308bc7b4243b0cfddfc836b4b523b259699e98d Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Tue, 5 Oct 2021 00:39:49 +0200 Subject: [PATCH] Move all derive macros and derive macro attributes to gdnative::derive --- examples/array_export/src/lib.rs | 2 +- examples/hello_world/src/lib.rs | 2 +- examples/resource/src/lib.rs | 4 ++-- examples/scene_create/src/lib.rs | 10 +++++----- examples/spinning_cube/src/lib.rs | 4 ++-- gdnative-core/src/nativescript/macros.rs | 2 +- gdnative-derive/src/lib.rs | 2 +- gdnative/src/lib.rs | 5 +++-- test/src/test_derive.rs | 2 +- 9 files changed, 17 insertions(+), 16 deletions(-) diff --git a/examples/array_export/src/lib.rs b/examples/array_export/src/lib.rs index b17b6d7a3..bd83bac4f 100644 --- a/examples/array_export/src/lib.rs +++ b/examples/array_export/src/lib.rs @@ -6,7 +6,7 @@ use gdnative::prelude::*; #[register_with(Self::register)] struct ExportsArrays; -#[gdnative::methods] +#[methods] impl ExportsArrays { fn new(_owner: &Node) -> Self { ExportsArrays diff --git a/examples/hello_world/src/lib.rs b/examples/hello_world/src/lib.rs index c2395aba4..3543e8814 100644 --- a/examples/hello_world/src/lib.rs +++ b/examples/hello_world/src/lib.rs @@ -4,7 +4,7 @@ use gdnative::prelude::*; #[inherit(Node)] struct HelloWorld; -#[gdnative::methods] +#[methods] impl HelloWorld { fn new(_owner: &Node) -> Self { HelloWorld diff --git a/examples/resource/src/lib.rs b/examples/resource/src/lib.rs index 32a8fb017..faeda54e9 100644 --- a/examples/resource/src/lib.rs +++ b/examples/resource/src/lib.rs @@ -8,7 +8,7 @@ struct GreetingResource { name: String, } -#[gdnative::methods] +#[methods] impl GreetingResource { fn new(_owner: &Resource) -> Self { Self { name: "".into() } @@ -29,7 +29,7 @@ struct Greeter { greeting_resource: Option>, } -#[gdnative::methods] +#[methods] impl Greeter { fn new(_owner: &Node) -> Self { Greeter { diff --git a/examples/scene_create/src/lib.rs b/examples/scene_create/src/lib.rs index 3e3558eb4..893e8aacc 100644 --- a/examples/scene_create/src/lib.rs +++ b/examples/scene_create/src/lib.rs @@ -6,7 +6,7 @@ pub enum ManageErrs { RootClassNotSpatial(String), } -#[derive(gdnative::NativeClass)] +#[derive(gdnative::derive::NativeClass)] #[inherit(Spatial)] struct SceneCreate { // Store the loaded scene for a very slight performance boost but mostly to show you how. @@ -24,7 +24,7 @@ struct SceneCreate { // Note, the same mechanism which is used to call from panel into spawn_one and remove_one can be // used to call other GDNative classes here in rust. -#[gdnative::methods] +#[gdnative::derive::methods] impl SceneCreate { fn new(_owner: &Spatial) -> Self { SceneCreate { @@ -33,7 +33,7 @@ impl SceneCreate { } } - #[export] + #[gdnative::derive::export] fn _ready(&mut self, _owner: &Spatial) { self.template = load_scene("res://Child_scene.tscn"); match &self.template { @@ -42,7 +42,7 @@ impl SceneCreate { } } - #[export] + #[gdnative::derive::export] fn spawn_one(&mut self, owner: &Spatial, message: GodotString) { godot_print!("Called spawn_one({})", message.to_string()); @@ -77,7 +77,7 @@ impl SceneCreate { update_panel(owner, num_children); } - #[export] + #[gdnative::derive::export] fn remove_one(&mut self, owner: &Spatial, str: GodotString) { godot_print!("Called remove_one({})", str); let num_children = owner.get_child_count(); diff --git a/examples/spinning_cube/src/lib.rs b/examples/spinning_cube/src/lib.rs index aefa1a579..20085b1d9 100644 --- a/examples/spinning_cube/src/lib.rs +++ b/examples/spinning_cube/src/lib.rs @@ -3,7 +3,7 @@ use gdnative::prelude::*; use gdnative::nativescript::init::property::{EnumHint, IntHint, StringHint}; -#[derive(gdnative::NativeClass)] +#[derive(gdnative::derive::NativeClass)] #[inherit(MeshInstance)] #[register_with(register_properties)] struct RustTest { @@ -36,7 +36,7 @@ fn register_properties(builder: &ClassBuilder) { .done(); } -#[gdnative::methods] +#[methods] impl RustTest { fn new(_owner: &MeshInstance) -> Self { RustTest { diff --git a/gdnative-core/src/nativescript/macros.rs b/gdnative-core/src/nativescript/macros.rs index 437b6eaae..d8974605b 100644 --- a/gdnative-core/src/nativescript/macros.rs +++ b/gdnative-core/src/nativescript/macros.rs @@ -98,7 +98,7 @@ macro_rules! godot_wrap_method_inner { struct ThisMethod; use $crate::nativescript::{NativeClass, Instance, RefInstance, OwnerArg}; - use ::gdnative::FromVarargs; + use ::gdnative::derive::FromVarargs; #[derive(FromVarargs)] #[allow(clippy::used_underscore_binding)] diff --git a/gdnative-derive/src/lib.rs b/gdnative-derive/src/lib.rs index 1266170f4..caabc729e 100644 --- a/gdnative-derive/src/lib.rs +++ b/gdnative-derive/src/lib.rs @@ -63,7 +63,7 @@ mod variant; /// ``` /// **Important**: Only one `impl` block per struct may be attributed with `#[methods]`. /// -/// For more context, please refer to [gdnative::NativeClass](NativeClass). +/// For more context, please refer to [gdnative::derive::NativeClass](NativeClass). #[proc_macro_attribute] pub fn methods(meta: TokenStream, input: TokenStream) -> TokenStream { if syn::parse::(meta.clone()).is_err() { diff --git a/gdnative/src/lib.rs b/gdnative/src/lib.rs index 3e22ba3a9..61fbd0d3e 100644 --- a/gdnative/src/lib.rs +++ b/gdnative/src/lib.rs @@ -66,13 +66,14 @@ pub use gdnative_core::{ #[doc(hidden)] pub use gdnative_core::*; +/// Derive macros and macro attributes. #[doc(inline)] -pub use gdnative_derive::*; +pub use gdnative_derive as derive; /// Curated re-exports of common items. pub mod prelude; +/// Bindings for the Godot Class API. #[doc(inline)] #[cfg(feature = "bindings")] -/// Bindings for the Godot Class API. pub use gdnative_bindings as api; diff --git a/test/src/test_derive.rs b/test/src/test_derive.rs index 74c314a3b..55717847f 100644 --- a/test/src/test_derive.rs +++ b/test/src/test_derive.rs @@ -173,7 +173,7 @@ fn test_derive_owned_to_variant() -> bool { ok } -#[derive(gdnative::NativeClass)] +#[derive(gdnative::derive::NativeClass)] #[inherit(Node)] struct PropertyHooks { #[property(