@@ -173,15 +173,17 @@ use crate::registry::property::{BuiltinExport, Export, Var};
173
173
///
174
174
/// When used with `#[class(tool)]`, the before-ready checks are omitted.
175
175
/// Otherwise, `OnEditor<T>` behaves the same — accessing an uninitialized value will cause a panic.
176
+ #[ derive( Debug ) ]
176
177
pub struct OnEditor < T > {
177
- inner : OnEditorState < T > ,
178
+ state : OnEditorState < T > ,
178
179
}
179
180
181
+ #[ derive( Debug ) ]
180
182
pub ( crate ) enum OnEditorState < T > {
181
183
/// Uninitialized null value.
182
- Null ,
184
+ UninitNull ,
183
185
/// Uninitialized state, but with a value marked as invalid (required to represent non-nullable type in the editor).
184
- Uninitialized ( T ) ,
186
+ UninitSentinel ( T ) ,
185
187
/// Initialized with a value.
186
188
Initialized ( T ) ,
187
189
}
@@ -195,10 +197,10 @@ impl<T: Var + FromGodot + PartialEq> OnEditor<T> {
195
197
/// # Panics
196
198
/// If `init()` was called before.
197
199
pub fn init ( & mut self , val : T ) {
198
- match self . inner {
199
- OnEditorState :: Null | OnEditorState :: Uninitialized ( _) => {
200
+ match self . state {
201
+ OnEditorState :: UninitNull | OnEditorState :: UninitSentinel ( _) => {
200
202
* self = OnEditor {
201
- inner : OnEditorState :: Initialized ( val) ,
203
+ state : OnEditorState :: Initialized ( val) ,
202
204
} ;
203
205
}
204
206
OnEditorState :: Initialized ( _) => {
@@ -215,7 +217,7 @@ impl<T: Var + FromGodot + PartialEq> OnEditor<T> {
215
217
T :: Via : BuiltinExport ,
216
218
{
217
219
OnEditor {
218
- inner : OnEditorState :: Uninitialized ( val) ,
220
+ state : OnEditorState :: UninitSentinel ( val) ,
219
221
}
220
222
}
221
223
@@ -224,23 +226,23 @@ impl<T: Var + FromGodot + PartialEq> OnEditor<T> {
224
226
/// Not a part of public API – available only via `Default` implementation on `OnEditor<Gd<T>>` and `OnEditor<DynGd<D, T>>`.
225
227
pub ( crate ) fn gd_invalid ( ) -> Self {
226
228
OnEditor {
227
- inner : OnEditorState :: Null ,
229
+ state : OnEditorState :: UninitNull ,
228
230
}
229
231
}
230
232
231
233
#[ doc( hidden) ]
232
234
pub fn is_invalid ( & self ) -> bool {
233
- match self . inner {
234
- OnEditorState :: Null | OnEditorState :: Uninitialized ( _) => true ,
235
+ match self . state {
236
+ OnEditorState :: UninitNull | OnEditorState :: UninitSentinel ( _) => true ,
235
237
OnEditorState :: Initialized ( _) => false ,
236
238
}
237
239
}
238
240
239
241
/// `Var::get_property` implementation that works both for nullable and non-nullable types.
240
242
pub ( crate ) fn get_property_inner ( & self ) -> Option < T :: Via > {
241
- match & self . inner {
242
- OnEditorState :: Null => None ,
243
- OnEditorState :: Uninitialized ( val) | OnEditorState :: Initialized ( val) => {
243
+ match & self . state {
244
+ OnEditorState :: UninitNull => None ,
245
+ OnEditorState :: UninitSentinel ( val) | OnEditorState :: Initialized ( val) => {
244
246
Some ( val. get_property ( ) )
245
247
}
246
248
}
@@ -251,18 +253,18 @@ impl<T: Var + FromGodot + PartialEq> OnEditor<T> {
251
253
/// All the state transitions are valid, since it is being run only in the editor.
252
254
/// See also [`Option::set_property()`].
253
255
pub ( crate ) fn set_property_inner ( & mut self , value : Option < T :: Via > ) {
254
- match ( value, & mut self . inner ) {
255
- ( None , _) => self . inner = OnEditorState :: Null ,
256
+ match ( value, & mut self . state ) {
257
+ ( None , _) => self . state = OnEditorState :: UninitNull ,
256
258
( Some ( value) , OnEditorState :: Initialized ( current_value) ) => {
257
259
current_value. set_property ( value) ;
258
260
}
259
- ( Some ( value) , OnEditorState :: Null ) => {
260
- self . inner = OnEditorState :: Initialized ( FromGodot :: from_godot ( value) )
261
+ ( Some ( value) , OnEditorState :: UninitNull ) => {
262
+ self . state = OnEditorState :: Initialized ( FromGodot :: from_godot ( value) )
261
263
}
262
- ( Some ( value) , OnEditorState :: Uninitialized ( current_value) ) => {
264
+ ( Some ( value) , OnEditorState :: UninitSentinel ( current_value) ) => {
263
265
let value = FromGodot :: from_godot ( value) ;
264
266
if value != * current_value {
265
- self . inner = OnEditorState :: Initialized ( value)
267
+ self . state = OnEditorState :: Initialized ( value)
266
268
}
267
269
}
268
270
}
@@ -272,8 +274,8 @@ impl<T: Var + FromGodot + PartialEq> OnEditor<T> {
272
274
impl < T > std:: ops:: Deref for OnEditor < T > {
273
275
type Target = T ;
274
276
fn deref ( & self ) -> & Self :: Target {
275
- match & self . inner {
276
- OnEditorState :: Null | OnEditorState :: Uninitialized ( _) => {
277
+ match & self . state {
278
+ OnEditorState :: UninitNull | OnEditorState :: UninitSentinel ( _) => {
277
279
panic ! ( "OnEditor field hasn't been initialized." )
278
280
}
279
281
OnEditorState :: Initialized ( v) => v,
@@ -283,8 +285,8 @@ impl<T> std::ops::Deref for OnEditor<T> {
283
285
284
286
impl < T > std:: ops:: DerefMut for OnEditor < T > {
285
287
fn deref_mut ( & mut self ) -> & mut Self :: Target {
286
- match & mut self . inner {
287
- OnEditorState :: Null | OnEditorState :: Uninitialized ( _) => {
288
+ match & mut self . state {
289
+ OnEditorState :: UninitNull | OnEditorState :: UninitSentinel ( _) => {
288
290
panic ! ( "OnEditor field hasn't been initialized." )
289
291
}
290
292
OnEditorState :: Initialized ( v) => v,
@@ -307,7 +309,7 @@ where
307
309
T :: Via : BuiltinExport ,
308
310
{
309
311
fn get_property ( & self ) -> Self :: Via {
310
- // Will never fail – `PrimitiveGodotType` can not be represented by the `OnEditorState::Null `.
312
+ // Will never fail – `PrimitiveGodotType` can not be represented by the `OnEditorState::UninitNull `.
311
313
OnEditor :: < T > :: get_property_inner ( self ) . expect ( "DirectExport is not nullable." )
312
314
}
313
315
0 commit comments