Skip to content

Commit 430cc6c

Browse files
committed
feat: Change the constraint of PhantomVar on GodotType to GodotConvert
1 parent 554f309 commit 430cc6c

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

godot-codegen/src/generator/enums.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ pub fn make_enum_definition_with(
153153

154154
#var_trait_set_property
155155
}
156+
157+
impl crate::registry::property::Export for #name {}
156158
}
157159
});
158160

godot-core/src/registry/property/phantom_var.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::fmt;
1010
use std::hash::{Hash, Hasher};
1111
use std::marker::PhantomData;
1212

13-
use crate::meta::{ClassId, GodotConvert, GodotType, PropertyHintInfo};
13+
use crate::meta::{ClassId, GodotConvert, PropertyHintInfo};
1414
use crate::registry::property::{Export, Var};
1515

1616
/// A zero-sized type for creating a property without a backing field, accessible only through custom getter/setter functions.
@@ -55,15 +55,15 @@ use crate::registry::property::{Export, Var};
5555
/// This field can now be accessed from GDScript as `banner.text`.
5656
// Bounds for T are somewhat un-idiomatically directly on the type, rather than impls.
5757
// This improves error messages in IDEs when using the type as a field.
58-
pub struct PhantomVar<T: GodotType + Var>(PhantomData<T>);
58+
pub struct PhantomVar<T: GodotConvert + Var>(PhantomData<T>);
5959

60-
impl<T: GodotType + Var> GodotConvert for PhantomVar<T> {
61-
type Via = T;
60+
impl<T: GodotConvert + Var> GodotConvert for PhantomVar<T> {
61+
type Via = <T as GodotConvert>::Via;
6262
}
6363

6464
// `PhantomVar` supports only part of `Var`, but it has to implement it, otherwise we cannot implement `Export` either.
6565
// The `GodotClass` derive macro should ensure that the `Var` implementation is not used.
66-
impl<T: GodotType + Var> Var for PhantomVar<T> {
66+
impl<T: GodotConvert + Var> Var for PhantomVar<T> {
6767
fn get_property(&self) -> Self::Via {
6868
unreachable!("code generated by GodotClass should call the custom getter")
6969
}
@@ -78,7 +78,7 @@ impl<T: GodotType + Var> Var for PhantomVar<T> {
7878
}
7979

8080
// Reuse values from `T`, if any.
81-
impl<T: GodotType + Var + Export> Export for PhantomVar<T> {
81+
impl<T: GodotConvert + Var + Export> Export for PhantomVar<T> {
8282
fn export_hint() -> PropertyHintInfo {
8383
<T as Export>::export_hint()
8484
}
@@ -88,7 +88,7 @@ impl<T: GodotType + Var + Export> Export for PhantomVar<T> {
8888
}
8989
}
9090

91-
impl<T: GodotType + Var> Default for PhantomVar<T> {
91+
impl<T: GodotConvert + Var> Default for PhantomVar<T> {
9292
fn default() -> Self {
9393
Self(Default::default())
9494
}
@@ -97,49 +97,49 @@ impl<T: GodotType + Var> Default for PhantomVar<T> {
9797
// Like `PhantomData` from the Rust standard library, `PhantomVar` implements many common traits like `Eq` and `Hash`
9898
// to allow these traits to be derived on containing structs as well.
9999

100-
impl<T: GodotType + Var> Clone for PhantomVar<T> {
100+
impl<T: GodotConvert + Var> Clone for PhantomVar<T> {
101101
fn clone(&self) -> Self {
102102
*self
103103
}
104104
}
105105

106-
impl<T: GodotType + Var> Copy for PhantomVar<T> {}
106+
impl<T: GodotConvert + Var> Copy for PhantomVar<T> {}
107107

108-
impl<T: GodotType + Var> fmt::Debug for PhantomVar<T> {
108+
impl<T: GodotConvert + Var> fmt::Debug for PhantomVar<T> {
109109
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
110110
f.debug_tuple("PhantomVar").finish()
111111
}
112112
}
113113

114-
impl<T: GodotType + Var> PartialEq for PhantomVar<T> {
114+
impl<T: GodotConvert + Var> PartialEq for PhantomVar<T> {
115115
fn eq(&self, _other: &Self) -> bool {
116116
true
117117
}
118118
}
119119

120-
impl<T: GodotType + Var> Eq for PhantomVar<T> {}
120+
impl<T: GodotConvert + Var> Eq for PhantomVar<T> {}
121121

122-
impl<T: GodotType + Var> PartialOrd for PhantomVar<T> {
122+
impl<T: GodotConvert + Var> PartialOrd for PhantomVar<T> {
123123
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
124124
Some(self.cmp(other))
125125
}
126126
}
127127

128-
impl<T: GodotType + Var> Ord for PhantomVar<T> {
128+
impl<T: GodotConvert + Var> Ord for PhantomVar<T> {
129129
fn cmp(&self, _other: &Self) -> Ordering {
130130
Ordering::Equal
131131
}
132132
}
133133

134-
impl<T: GodotType + Var> Hash for PhantomVar<T> {
134+
impl<T: GodotConvert + Var> Hash for PhantomVar<T> {
135135
fn hash<H: Hasher>(&self, _state: &mut H) {}
136136
}
137137

138138
// SAFETY: This type contains no data.
139-
unsafe impl<T: GodotType + Var> Send for PhantomVar<T> {}
139+
unsafe impl<T: GodotConvert + Var> Send for PhantomVar<T> {}
140140

141141
// SAFETY: This type contains no data.
142-
unsafe impl<T: GodotType + Var> Sync for PhantomVar<T> {}
142+
unsafe impl<T: GodotConvert + Var> Sync for PhantomVar<T> {}
143143

144144
/// This type exists only as a place to add `compile_fail` doctests for `PhantomVar`, which do not need to be in the public documentation.
145145
///

0 commit comments

Comments
 (0)