Iced: JSX/HTML-like declarative macros to construct Element

Created on 19 Jun 2020  路  2Comments  路  Source: hecrj/iced

Instead of:

let element: Element<'_, Message> = Column::new()
  .style(column_style)
  .push(
    Button::new(button_state, Text::new("abc"))
      .style(button_style)
      .on_press(on_press)
  )
  .push(Text::new("output"))
  .into()

I would prefer:

let element: Element<'_, Message> = iced::rsx! {
  <Column style={column_style}>
    <Button on_press={on_press} style={button_style}>
      <Text>abc</Text>
    </Button>
    <Text>output</Text>
  </Column>
}.into()
question

Most helpful comment

It's important to note that these macros could be built on top of iced by anyone, as they are just rewriting calls to the public API.

Personally, I am not convinced. I shared some of my thoughts on this in #61. In the end, I believe the improvement here is very subjective and I'd like to see some more discussion and exploration.

All 2 comments

It's important to note that these macros could be built on top of iced by anyone, as they are just rewriting calls to the public API.

Personally, I am not convinced. I shared some of my thoughts on this in #61. In the end, I believe the improvement here is very subjective and I'd like to see some more discussion and exploration.

You can refer to yew or typed-html in this regard, but the combination of native rust syntax and XML-like syntax is not perfect.

And I think the main problem is that the IDE does not support such macros enough, it cannot detect the type, rename and refactor.

Maybe the rust team can solve these problems in the future by standardizing an rsx format 馃榾.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

casperstorm picture casperstorm  路  3Comments

cetra3 picture cetra3  路  3Comments

kszlim picture kszlim  路  4Comments

jiminycrick picture jiminycrick  路  3Comments

olanod picture olanod  路  4Comments