[−][src]Macro cnx::cnx_add_widget
Adds a Widget
to a Cnx
instance.
This macro adds a Widget
to a Cnx
instance, placing it to the right
of any existing widgets. (Internally, this macro uses
Cnx::add_widget()
).
This macro serves two purposes:
-
It avoids lexical-lifetime issues in the borrow checker, if the
Widget
's constructor borrows theCnx
instance and is constructed as part of the same statement where it's added to theCnx
instance.For instance, this works:
ⓘThis example is not testedcnx_add_widget!(cnx, DummyWidget::new(&cnx)))
Whereas this doesn't pass borrow checking:
ⓘThis example is not testedcnx.add_widget(DummyWidget::new(&cnx))
-
It might one day grow into a more complex DSL to pass configurable attributes through to widgets.