Open Cogitri opened 3 years ago
(or maybe even when compiling)
I suppose since the struct is being processed by the CompositeTemplate
proc macro, this would indeed be possible.
It would also be possible to make it less verbose by either having #[template_child]
automatically wrap a member with TemplateChild
, or removing #[template_child]
and auto-detecting TemplateChild
members. The former seems too magical and unclear, the latter might be alright.
The issue with the second suggestion is that you can no longer set a different id for the type or mark it as internal-child.
The first suggestion cannot be done without making it an attribute macro. At bare minimum we probably want to use the better error message from TemplateChild::get
inside that Deref
impl.
The other things we do can are:
resource
templates. We can only do null checking here, not type checking.init_template
. This should work in all cases.TemplateChild
and throw a warning
When I have a struct like:
And init it like so:
I don't get any error message during compilation or when creating the object. However, once I access
add_data_button
, the app crashes:Which makes sense, but it'd be nice if it either crashed during construction with a more helpful error message (or maybe even when compiling).
Tested w/ e0cbea57