[][src]Macro cnx::cnx_add_widget

macro_rules! cnx_add_widget {
    ($cnx:ident, $widget:expr) => { ... };
}

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 the Cnx instance and is constructed as part of the same statement where it's added to the Cnx instance.

    For instance, this works:

    This example is not tested
    cnx_add_widget!(cnx, DummyWidget::new(&cnx)))

    Whereas this doesn't pass borrow checking:

    This example is not tested
    cnx.add_widget(DummyWidget::new(&cnx))
  • It might one day grow into a more complex DSL to pass configurable attributes through to widgets.