Skip to content

Commit 6c896d2

Browse files
authored
Try #229:
2 parents 230480d + 07758fe commit 6c896d2

File tree

5 files changed

+9
-13
lines changed

5 files changed

+9
-13
lines changed

godot-core/src/builtin/array.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -883,12 +883,7 @@ struct TypeInfo {
883883
impl TypeInfo {
884884
fn new<T: VariantMetadata>() -> Self {
885885
let variant_type = T::variant_type();
886-
let class_name = match variant_type {
887-
VariantType::Object => StringName::from(T::class_name()),
888-
// TODO for variant types other than Object, class_name() returns "(no base)"; just
889-
// make it return "" instead?
890-
_ => StringName::default(),
891-
};
886+
let class_name: StringName = T::class_name().unwrap_or_default().into();
892887
Self {
893888
variant_type,
894889
class_name,

godot-core/src/builtin/meta/class_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::obj::GodotClass;
1313

1414
/// Utility to construct class names known at compile time.
1515
/// Cannot be a function since the backing string must be retained.
16-
#[derive(Eq, PartialEq, Hash, Clone, Debug)]
16+
#[derive(Default, Eq, PartialEq, Hash, Clone, Debug)]
1717
pub struct ClassName {
1818
backing: StringName,
1919
}

godot-core/src/builtin/meta/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ use godot_ffi as sys;
2222
pub trait VariantMetadata {
2323
fn variant_type() -> VariantType;
2424

25-
fn class_name() -> ClassName {
26-
ClassName::of::<()>() // FIXME Option or so
25+
fn class_name() -> Option<ClassName> {
26+
// If we use `ClassName::of::<()>()` then this type shows up as `(no base)` in documentation.
27+
None
2728
}
2829

2930
fn property_info(property_name: &str) -> PropertyInfo {
3031
PropertyInfo {
3132
variant_type: Self::variant_type(),
32-
class_name: Self::class_name(),
33+
class_name: Self::class_name().unwrap_or_default(),
3334
property_name: StringName::from(property_name),
3435
hint: global::PropertyHint::PROPERTY_HINT_NONE,
3536
hint_string: GodotString::new(),

godot-core/src/builtin/variant/impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl VariantMetadata for Variant {
229229
fn property_info(property_name: &str) -> PropertyInfo {
230230
PropertyInfo {
231231
variant_type: Self::variant_type(),
232-
class_name: Self::class_name(),
232+
class_name: Self::class_name().unwrap_or_default(),
233233
property_name: StringName::from(property_name),
234234
hint: global::PropertyHint::PROPERTY_HINT_NONE,
235235
hint_string: GodotString::new(),

godot-core/src/obj/gd.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,8 @@ impl<T: GodotClass> VariantMetadata for Gd<T> {
709709
VariantType::Object
710710
}
711711

712-
fn class_name() -> ClassName {
713-
ClassName::of::<T>()
712+
fn class_name() -> Option<ClassName> {
713+
Some(ClassName::of::<T>())
714714
}
715715
}
716716

0 commit comments

Comments
 (0)