Skip to content

Commit 1b34b7c

Browse files
committed
Reduce nesting in nativescript::export module
Changes: * Move out symbols from export::{method, property} * Flatten property::accessor::invalid * Rename Usage -> PropertyUsage (like the already re-exported version)
1 parent 46a271f commit 1b34b7c

File tree

15 files changed

+59
-68
lines changed

15 files changed

+59
-68
lines changed

examples/array_export/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use gdnative::nativescript::export::property::hint::{ArrayHint, IntHint, RangeHint};
1+
use gdnative::nativescript::export::hint::{ArrayHint, IntHint, RangeHint};
22
use gdnative::prelude::*;
33

44
#[derive(NativeClass)]

examples/spinning_cube/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use gdnative::api::MeshInstance;
22
use gdnative::prelude::*;
33

4-
use gdnative::nativescript::export::property::{EnumHint, IntHint, StringHint};
4+
use gdnative::nativescript::export::hint::{EnumHint, IntHint, StringHint};
55

66
#[derive(gdnative::derive::NativeClass)]
77
#[inherit(MeshInstance)]

gdnative-async/src/rt/bridge.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use parking_lot::Mutex;
66
use gdnative_bindings::{Object, Reference};
77
use gdnative_core::core_types::{GodotError, Variant, VariantArray};
88
use gdnative_core::godot_site;
9-
use gdnative_core::nativescript::export::method::{Method, Varargs};
10-
use gdnative_core::nativescript::export::ClassBuilder;
9+
use gdnative_core::nativescript::export::{ClassBuilder, Method, Varargs};
1110
use gdnative_core::nativescript::user_data::{ArcData, Map};
1211
use gdnative_core::nativescript::{Instance, NativeClass, NativeClassMethods, RefInstance};
1312
use gdnative_core::object::{ownership::Shared, TRef};

gdnative-async/src/rt/func_state.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
use gdnative_bindings::Reference;
22
use gdnative_core::core_types::{ToVariant, Variant, VariantType};
33
use gdnative_core::godot_site;
4-
use gdnative_core::nativescript::export::method::StaticArgs;
5-
use gdnative_core::nativescript::export::method::StaticArgsMethod;
64
use gdnative_core::nativescript::export::{
7-
ClassBuilder, ExportInfo, PropertyUsage, Signal, SignalArgument,
5+
ClassBuilder, ExportInfo, PropertyUsage, Signal, SignalArgument, StaticArgs, StaticArgsMethod,
86
};
9-
use gdnative_core::nativescript::user_data::LocalCellData;
10-
use gdnative_core::nativescript::user_data::{Map, MapMut};
7+
use gdnative_core::nativescript::user_data::{LocalCellData, Map, MapMut};
118
use gdnative_core::nativescript::{Instance, NativeClass, NativeClassMethods, RefInstance};
129
use gdnative_core::object::ownership::{Shared, Unique};
1310
use gdnative_derive::FromVarargs;

gdnative-core/src/nativescript/export.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,41 @@
3333
// Temporary for unsafe method registration
3434
#![allow(deprecated)]
3535

36-
use crate::*;
37-
3836
use std::ffi::CString;
3937
use std::marker::PhantomData;
4038
use std::ptr;
4139

42-
use crate::core_types::{GodotString, Variant};
40+
use crate::core_types::{GodotString, ToVariant, Variant};
41+
use crate::nativescript::{class_registry, emplace};
4342
use crate::nativescript::{user_data::UserData, NativeClass, NativeClassMethods};
44-
use crate::object::{GodotObject, NewRef, TRef};
43+
use crate::object::{GodotObject, NewRef, RawObject, TRef};
4544
use crate::private::get_api;
4645

47-
use super::class_registry;
48-
use super::emplace;
46+
pub use method::*;
47+
pub use property::*;
48+
49+
mod method;
50+
mod property;
4951

50-
pub mod method;
51-
pub mod property;
52+
//pub use self::method::{
53+
// Method, MethodBuilder, RpcMode, ScriptMethod, ScriptMethodAttributes, ScriptMethodFn, Varargs,
54+
//};
55+
//pub use self::property::{ExportInfo, PropertyBuilder, Usage as PropertyUsage};
5256

53-
pub use self::method::{
54-
Method, MethodBuilder, RpcMode, ScriptMethod, ScriptMethodAttributes, ScriptMethodFn, Varargs,
55-
};
56-
pub use self::property::{Export, ExportInfo, PropertyBuilder, Usage as PropertyUsage};
57+
/// Trait for exportable types.
58+
pub trait Export: ToVariant {
59+
/// A type-specific hint type that is valid for the type being exported.
60+
///
61+
/// If this type shows up as `NoHint`, a private, uninhabitable type indicating
62+
/// that there are no hints available for the time being, users *must* use `None`
63+
/// for properties of this type. This ensures that it will not be a breaking change
64+
/// to add a hint for the type later, since it supports no operations and cannot
65+
/// be named directly in user code.
66+
type Hint;
67+
68+
/// Returns `ExportInfo` given an optional typed hint.
69+
fn export_info(hint: Option<Self::Hint>) -> ExportInfo;
70+
}
5771

5872
/// A handle that can register new classes to the engine during initialization.
5973
///
@@ -124,7 +138,7 @@ impl InitHandle {
124138
}
125139
};
126140

127-
let owner = match object::RawObject::<C::Base>::try_from_sys_ref(this) {
141+
let owner = match RawObject::<C::Base>::try_from_sys_ref(this) {
128142
Some(owner) => owner,
129143
None => {
130144
godot_error!(

gdnative-core/src/nativescript/export/property.rs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,21 @@
11
//! Property registration.
22
3+
use accessor::{Getter, RawGetter, RawSetter, Setter};
4+
use invalid_accessor::{InvalidGetter, InvalidSetter};
5+
36
use crate::core_types::*;
47
use crate::nativescript::{Instance, NativeClass};
58
use crate::object::ownership::Shared;
69
use crate::object::GodotObject;
710
use crate::object::Ref;
811
use crate::private::get_api;
912

10-
use super::ClassBuilder;
13+
use super::{ClassBuilder, Export};
1114

1215
mod accessor;
13-
pub mod hint;
14-
15-
pub use hint::*;
16-
17-
use accessor::{Getter, InvalidGetter, InvalidSetter, RawGetter, RawSetter, Setter};
16+
mod invalid_accessor;
1817

19-
/// Trait for exportable types.
20-
pub trait Export: ToVariant {
21-
/// A type-specific hint type that is valid for the type being exported.
22-
///
23-
/// If this type shows up as `NoHint`, a private, uninhabitable type indicating
24-
/// that there are no hints available for the time being, users *must* use `None`
25-
/// for properties of this type. This ensures that it will not be a breaking change
26-
/// to add a hint for the type later, since it supports no operations and cannot
27-
/// be named directly in user code.
28-
type Hint;
29-
30-
/// Returns `ExportInfo` given an optional typed hint.
31-
fn export_info(hint: Option<Self::Hint>) -> ExportInfo;
32-
}
18+
pub mod hint;
3319

3420
/// Metadata about the exported property.
3521
#[derive(Debug)]
@@ -73,7 +59,7 @@ pub struct PropertyBuilder<'a, C, T: Export, S = InvalidSetter<'a>, G = InvalidG
7359
getter: G,
7460
default: Option<T>,
7561
hint: Option<T::Hint>,
76-
usage: Usage,
62+
usage: PropertyUsage,
7763
class_builder: &'a ClassBuilder<C>,
7864
}
7965

@@ -91,7 +77,7 @@ where
9177
getter: InvalidGetter::new(name),
9278
default: None,
9379
hint: None,
94-
usage: Usage::DEFAULT,
80+
usage: PropertyUsage::DEFAULT,
9581
class_builder,
9682
}
9783
}
@@ -283,14 +269,14 @@ where
283269

284270
/// Sets a property usage.
285271
#[inline]
286-
pub fn with_usage(mut self, usage: Usage) -> Self {
272+
pub fn with_usage(mut self, usage: PropertyUsage) -> Self {
287273
self.usage = usage;
288274
self
289275
}
290276
}
291277

292278
bitflags::bitflags! {
293-
pub struct Usage: u32 {
279+
pub struct PropertyUsage: u32 {
294280
const STORAGE = sys::godot_property_usage_flags_GODOT_PROPERTY_USAGE_STORAGE as u32;
295281
const EDITOR = sys::godot_property_usage_flags_GODOT_PROPERTY_USAGE_EDITOR as u32;
296282
const NETWORK = sys::godot_property_usage_flags_GODOT_PROPERTY_USAGE_NETWORK as u32;
@@ -315,7 +301,7 @@ bitflags::bitflags! {
315301
}
316302
}
317303

318-
impl Usage {
304+
impl PropertyUsage {
319305
#[inline]
320306
pub fn to_sys(self) -> sys::godot_property_usage_flags {
321307
self.bits() as sys::godot_property_usage_flags
@@ -474,7 +460,7 @@ mod impl_export {
474460
}
475461

476462
impl Export for VariantArray<Shared> {
477-
type Hint = ArrayHint;
463+
type Hint = hint::ArrayHint;
478464

479465
#[inline]
480466
fn export_info(hint: Option<Self::Hint>) -> ExportInfo {

gdnative-core/src/nativescript/export/property/accessor.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ use crate::nativescript::user_data::{Map, MapMut, UserData};
88
use crate::nativescript::NativeClass;
99
use crate::object::{GodotObject, RawObject, TRef};
1010

11-
mod invalid;
12-
13-
pub use self::invalid::{InvalidGetter, InvalidSetter};
14-
1511
/// Trait for raw property setters.
1612
///
1713
/// This is an internal interface. User code should not use this directly.

gdnative-core/src/nativescript/export/property/hint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::{Export, ExportInfo};
1616
/// Basic usage:
1717
///
1818
/// ```rust
19-
/// use gdnative_core::nativescript::export::property::hint::RangeHint;
19+
/// use gdnative_core::nativescript::export::hint::RangeHint;
2020
///
2121
/// let hint: RangeHint<f64> = RangeHint::new(0.0, 20.0).or_greater();
2222
/// ```
@@ -110,7 +110,7 @@ where
110110
/// Basic usage:
111111
///
112112
/// ```rust
113-
/// use gdnative_core::nativescript::export::property::hint::EnumHint;
113+
/// use gdnative_core::nativescript::export::hint::EnumHint;
114114
///
115115
/// let hint = EnumHint::new(vec!["Foo".into(), "Bar".into(), "Baz".into()]);
116116
/// ```

gdnative-core/src/nativescript/export/property/accessor/invalid.rs renamed to gdnative-core/src/nativescript/export/property/invalid_accessor.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ use std::mem;
44

55
use crate::core_types::{FromVariant, ToVariant, Variant};
66
use crate::nativescript::NativeClass;
7-
use crate::*;
87

9-
use super::{RawGetter, RawSetter};
8+
use super::accessor::{RawGetter, RawSetter};
109

1110
/// Default setter used for a new property indicating that no valid setter is present. Outputs errors when invoked.
1211
#[derive(Debug)]

gdnative-core/src/nativescript/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ macro_rules! godot_wrap_method_inner {
108108
}
109109

110110
#[allow(unused_variables, unused_assignments, unused_mut)]
111-
impl $crate::nativescript::export::method::StaticArgsMethod<$type_name> for ThisMethod {
111+
impl $crate::nativescript::export::StaticArgsMethod<$type_name> for ThisMethod {
112112
type Args = Args;
113113
fn call(
114114
&self,
@@ -139,7 +139,7 @@ macro_rules! godot_wrap_method_inner {
139139
}
140140
}
141141

142-
$crate::nativescript::export::method::StaticArgs::new(ThisMethod)
142+
$crate::nativescript::export::StaticArgs::new(ThisMethod)
143143
}
144144
};
145145
}

0 commit comments

Comments
 (0)