Generic markup macro

Macros currently can't be used to express nodes of any type, with properties (that aren't "fields", but rather set_ prefixed methods) in arbitrary order and possibly omited. Example:

  • Note: general node methods are chainable. For instance, node.set_skin(skin) returns Node, node.append_children(iterable) returns Node and button.set_warning(is_warning) returns Arc<Button>.
  • Note: Here, Node holds an internal Arc<NonRefNode>.
  • I wish markup! { <Button warning={true}/> } to expand to:
Button::new(|btn| btn.set_warning(true))
  • I wish markup! { <Row></Row> } to expand to:
Row::new(|row| row).append_children([])
  • I wish markup! { <Button skin={specific_skin}/> } to expand to:
Button::new(|btn| btn).set_skin(Some(specific_skin))
// ... where `set_skin` comes from my base `Node` type, not `Button`

I think this macro would have to be designed at the language-level, requiring some constraints and some orientations given at the node itself, so that Rust knows what markup! has to do with the types.

I'd use that markup specifically NOT for writting websites, but rather generic applications, such as these developed with Unreal Engine, Adobe AIR, Flutter and Microsoft Silverlight.

Post from the other community:

If anyone interested...

This can't be done as a macro_rules! macro, but a proc macro already has the requisite power to do this, e.g. with syn-rsx. I highly doubt any support functionality would be added to std for this.


I had posted about whether this is possible in the other community and got no answers, so I had assumed Rust had no way of doing this.

If you mean Generic markup macro? - help - The Rust Programming Language Forum you did get an answer though.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.