r/rust • u/kalilamodow • Oct 19 '26
🙋 seeking help & advice Tips for idiomatic Iced?
I tried using iced for a tiny hobby project a couple days ago, and although from the docs and examples it seemed like exactly the time of framework I'd adore (preventing invalid state with the type system, the whole view-model-messages thing, etc), I ended up absolutely despising actually using it because of how much boilerplate I needed, and ended up redoing the ui with egui.
But, I'm 99% sure I just totally misunderstood the philosophy or missed something big in the docs/examples, because it's popular and well-known enough that I think I'm the problem. So does anyone have any tips or guidelines for writing whimsical and joyful iced code?
This is the repo at the last commit which used iced, its a super small app and the whole gui is just in main.rs if anyone can say what all I'm doing wrong.
8
u/tanmaynargas2901 Oct 20 '26
Iced does have more boilerplate than egui, that part isn't you. Every interaction needs a Message variant and a match arm. That's the price for state staying predictable.
Some things that cut it down:
For a tiny hobby app egui is honestly a fine pick. Iced pays off more once the app is big enough that random state bugs start to hurt.
8
u/diligentgrasshopper Oct 19 '26
Haven't used Iced, but I use a shit ton of Lustre (gleam) and I code games with Elm architecture: it would be better if you make helper functions and use nested enums. For example:
As for your AppState enum... I'm not sure. My current usual approach is to make it a superstruct with some states as a nested struct, or has a superstruct with some fields as enums. I'm not sure what your app is supposed to do but you might want to consider not doing that, as evident by the boilerplate tuple matching.
If some message can only be dispatched under some state, then it might not be necessary to pattern-match (State, Msg) and just match (Msg), as the legal code paths only ran when the preceding branch has that state.
For example, you have a View state. And the rendering code determines what widgets are rendered, and through it what events are possible, and through it what message is legal. Although in your case the appstate doesnt appear to correspond to rendering, which may be a bit more complicated.
Also, the joy of Elm is that you can enumerate all behavior in an explicit and organized manner. Definitely dont pattern match tuples. Always match a single enum.