Could Halogen be ported to Rust? (Which type-system features are missing?)

There is a framework that allows using Rust to write web frontends (it builds on stdweb[1], compiles to asm.js & WebAssembly).

I’ve been using it for a project in my spare time (after using Halogen at my job for a while)…
Unfortunately, yew is not as nice to use as Halogen, in several ways:

  • one can’t do async stuff (like ajax) “inline” in a Component’s update method (the equivalent of eval in Halogen). Instead it requires adding a new variant to the Msg enum (Msg is similar to Query in Halogen) and splitting the code up (like in Elm) to handle the result in another case handler.
  • querying child components is VERY cumbersome (especially when the child should return a value from the query) and can’t be done without changing the parent’s state, passing properties to the child and causing the parent’s DOM to be re-rendered (to actually pass the properties down). For letting the child respond, it requires passing a closure (which sends a Msg) down to it, as a property, that it calls with the response value. All this makes it very verbose and requires adding a lot of state to the parent component’s Model struct, that wouldn’t be required in Halogen.
    I described this issue in more detail here: https://github.com/DenisKolodin/yew/issues/350

I’d be very interested if you have any ideas how to use Rust’s type system better to get Halogen-like / type-safe querying of child components (incl. queries with return value from child to parent) without forcing the parent’s DOM to re-render and without having to add state to the parent component’s Model struct.
And to be able to do the querying by (something like a type-safe) SlotID instead of having to pass everything through properties. So my questions are:

  1. Do you have any ideas how Rust’s type system can be used in a better way to get Halogen-like levels of type-safe convenience for querying child components (incl. queries with return values) in yew?
    Btw, the frunk crate provides a Coproduct[2],. Do we also need EitherN / VariantF, lenses, SProxy etc.?

  2. Which type system features (that Rust doesn’t have yet) would be necessary to be able to port Halogen completely to Rust (without the async-inline requirement for now)? (separate from the yew project)

(The async-inline-ability is a separate/orthogonal concern. Rust doesn’t have HKTs (yet), so no monads, but it has futures (and async/await syntax[3] soon (currently with the mdo crate[4]) and generic associated types[5] in traits).)

Thanks! :slight_smile:


[1] crates[.]io/crates/stdweb
[2] crates[.]io/crates/frunk#coproduct
[3] github[.]com/rust-lang/rfcs/blob/master/text/2394-async_await.md
[4] github[.]com/danslapman/rust-mdo-future
[5] github[.]com/rust-lang/rfcs/blob/master/text/1598-generic_associated_types.md

(Sorry for breaking the links, I couldn’t submit without it: “Sorry, new users can only put 2 links in a post.”)

3 Likes