-
-
Notifications
You must be signed in to change notification settings - Fork 237
Closed
Labels
c: registerRegister classes, functions and other symbols to GDScriptRegister classes, functions and other symbols to GDScriptfeatureAdds functionality to the libraryAdds functionality to the library
Description
Currently the pattern for structs with Gd
references (which have to be manually initialized in ready
) looks like:
#[derive(GodotClass)]
#[class(base=Node)]
struct MyStruct {
my_child: Option<Gd<Node>>
#[base]
base: Base<Node>
}
Then, map
, unwrap
, or user-defined accessors are needed to bypass the Option
.
How about:
#[derive(GodotClass)]
#[class(base=Node)]
struct MyStruct {
#[on_ready("MyChild")]
my_child: OnReady<Gd<Node>>
#[base]
base: Base<Node>
}
where OnReady
is a MaybeUninit<Gd<T>>
with a Deref
/DerefMut
instance to avoid unwrapping.
It certainly clutters the struct definition a bit more, but you avoid:
- Initializing an
Option
inready
(which can easily be forgotten) - Using
map
or accessors to get the obviously initialized field - Paying for the
Option<Gd<T>>
's 16 bytes compared toGd<T>
Bear-03 and NoFr1ends
Metadata
Metadata
Assignees
Labels
c: registerRegister classes, functions and other symbols to GDScriptRegister classes, functions and other symbols to GDScriptfeatureAdds functionality to the libraryAdds functionality to the library